<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[When Running Python from NPP, the Script Can&#x27;t Find Local Image Files]]></title><description><![CDATA[<p dir="auto">I’m using the NppExec plugin to run Python and I’ve used a few variations to get this working, none of which allow the script to find local images. Here are the variations I’ve tried:</p>
<pre><code>cmd /K cd "$(FULL_CURRENT_DIRECTORY)" &amp; python "$(FULL_CURRENT_PATH)" &amp; pause &amp; exit
</code></pre>
<pre><code>cmd /k "$(FULL_CURRENT_PATH)"
</code></pre>
<pre><code>cmd /k c:\path\to\python.exe "$(FULL_CURRENT_PATH)"
</code></pre>
<pre><code>cmd /s /k "$(FULL_CURRENT_PATH)"
</code></pre>
<p dir="auto">And here’s an example script:</p>
<pre><code>from tkinter import *
from PIL import Image
#import sys
#import os
#
### get the execution path
#path  =  os.path.abspath(os.path.dirname(sys.argv[0]))
##
root  =  Tk()
root.title("Game")

frame  =  Frame(root)
frame.pack()

width = 700
height = 400
centre_x = width / 2
centre_y = height / 2

canvas  =  Canvas(frame, bg = "black", width = width, height = height)
canvas.pack()


#background  =  PhotoImage(file = path + "/images/for_loop_breakdown.png")
background  =  PhotoImage(file = "images/for_loop_breakdown.png")
canvas.create_image(centre_x, centre_y, image = background)

#character  =  PhotoImage(file = path + "/images/rectangle.png")
character  =  PhotoImage(file = "images/rectangle.png")
canvas.create_image(centre_x, centre_y, image = character)

root.mainloop()
</code></pre>
<p dir="auto">If I uncomment the lines defining the execution path as well as the lines below defining ‘background’ and ‘character’, everything works as expected. But as is, I get the following error:</p>
<pre><code>_tkinter.TclError: couldn't open "images/for_loop_breakdown.png": no such file or directory
</code></pre>
<p dir="auto">Can anyone point me in the right direction?<br />
Thanks.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/25435/when-running-python-from-npp-the-script-can-t-find-local-image-files</link><generator>RSS for Node</generator><lastBuildDate>Fri, 08 May 2026 07:55:59 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/25435.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 Jan 2024 16:40:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to When Running Python from NPP, the Script Can&#x27;t Find Local Image Files on Wed, 31 Jan 2024 14:07:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ron-tarrant-1" aria-label="Profile: Ron-Tarrant-1">@<bdi>Ron-Tarrant-1</bdi></a><br />
It’s okay. I found the answer on Stackoverflow. In case someone else comes looking for this, here’s the entire script (note the ‘-u’ arg after ‘py’):</p>
<pre><code>NPP_SAVE
cd "$(CURRENT_DIRECTORY)"
cmd.exe /c py -u "$(FILE_NAME)"
</code></pre>
<p dir="auto">Thanks again for all the help.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/92528</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92528</guid><dc:creator><![CDATA[Ron Tarrant 1]]></dc:creator><pubDate>Wed, 31 Jan 2024 14:07:09 GMT</pubDate></item><item><title><![CDATA[Reply to When Running Python from NPP, the Script Can&#x27;t Find Local Image Files on Wed, 31 Jan 2024 14:02:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a><br />
I’ve got a basic nppExec script working:</p>
<pre><code>NPP_SAVE
cd "$(CURRENT_DIRECTORY)"
cmd.exe /c py "$(FILE_NAME)"
</code></pre>
<p dir="auto">But print() statements in a Python script don’t show up in the console until after the script exits. This isn’t obvious unless Python opens a GUI window.</p>
<p dir="auto">Is there a way to have them show in real time as the script is executing?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/92527</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92527</guid><dc:creator><![CDATA[Ron Tarrant 1]]></dc:creator><pubDate>Wed, 31 Jan 2024 14:02:16 GMT</pubDate></item><item><title><![CDATA[Reply to When Running Python from NPP, the Script Can&#x27;t Find Local Image Files on Tue, 30 Jan 2024 23:51:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> Thank you for your kind response. My intention wasn’t to mislead. I’ve been labouring under the impression that nppExec was part and parcel of the Run dialog. Now I know better. I seriously don’t know how I got that impression, but there we are.</p>
<p dir="auto">And I appreciate you being considerate of my feelings in explaining things. I’ll go read up on nppExec now and hopefully get something working.</p>
<p dir="auto">Thank you.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/92518</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92518</guid><dc:creator><![CDATA[Ron Tarrant 1]]></dc:creator><pubDate>Tue, 30 Jan 2024 23:51:09 GMT</pubDate></item><item><title><![CDATA[Reply to When Running Python from NPP, the Script Can&#x27;t Find Local Image Files on Tue, 30 Jan 2024 22:18:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ron-tarrant-1" aria-label="Profile: Ron-Tarrant-1">@<bdi>Ron-Tarrant-1</bdi></a> said in <a href="/post/92511">When Running Python from NPP, the Script Can't Find Local Image Files</a>:</p>
<blockquote>
<p dir="auto">But the Run dialog only has one line.</p>
</blockquote>
<p dir="auto">In case Alan’s response wasn’t clear enough: if you have the NppExec plugin, you should use that for this task: trying to do it in the Run dialog will be fraught with difficulties.</p>
<p dir="auto">One of the main points of the NppExec plugin is to make something equivalent to a “batch” file language for N++, with lots of extra features compared to a true .bat file, which goes beyond the simple (and limiting) interface of the Run dialog.</p>
<p dir="auto">Since you said you have NppExec, then <em>use</em> it.  If you don’t actually have it, then install it, because it will make this and other such activities much simpler.</p>
<h1>In general: if your <strong>Run &gt; Run</strong> command involves any <code>&amp;&amp;</code> or <code>&amp;</code> or <code>||</code>, or more than one <code>$(...)</code> variable, switch to NppExec</h1>
]]></description><link>https://community.notepad-plus-plus.org/post/92515</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92515</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 30 Jan 2024 22:18:54 GMT</pubDate></item><item><title><![CDATA[Reply to When Running Python from NPP, the Script Can&#x27;t Find Local Image Files on Tue, 30 Jan 2024 20:44:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ron-tarrant-1" aria-label="Profile: Ron-Tarrant-1">@<bdi>Ron-Tarrant-1</bdi></a>:</p>
<p dir="auto">From this:</p>
<blockquote>
<p dir="auto">I’m using the NppExec plugin to run…</p>
</blockquote>
<p dir="auto">we were led to believe you were using NppExec.  Now you’re changing it up:</p>
<blockquote>
<p dir="auto">…But the Run dialog only has one line…</p>
</blockquote>
<p dir="auto">So, Peter’s reply is in the form of an NppExec script, because that’s what you said you were using.</p>
<hr />
<p dir="auto">Anyway, if you really want to use the <em>Run</em> dialog, you can put multiple commands in it, like this example:</p>
<p dir="auto"><code>cmd /c cd /d c:\ &amp;&amp; dir &amp;&amp; pause</code></p>
<p dir="auto">which changes to the root directory on C:, creates a directory listing there, and pauses before closing (so you can see that it worked).</p>
<p dir="auto">Note that if you <em>do</em> go with the <em>Run</em> dialog approach, you’d have to manually save your file first, as it won’t know what <code>npp_save</code> means.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/92513</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92513</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 30 Jan 2024 20:44:20 GMT</pubDate></item><item><title><![CDATA[Reply to When Running Python from NPP, the Script Can&#x27;t Find Local Image Files on Tue, 30 Jan 2024 19:44:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said in <a href="/post/92510">When Running Python from NPP, the Script Can't Find Local Image Files</a>:</p>
<blockquote>
<p dir="auto">npp_save<br />
cd “$(CURRENT_DIRECTORY)”<br />
cmd.exe /c python “$(FULL_CURRENT_PATH)”</p>
</blockquote>
<p dir="auto">Okay, I’m confused…</p>
<p dir="auto">I tried doing what you said… not putting everything on one line. But the Run dialog only has one line. So, I tried just spacing it out. $(CURRENT_DIRECTORY) and $(FILE_NAME) both expanded properly, but I got this error:</p>
<p dir="auto"><img src="/assets/uploads/files/1706643858319-2024-01-30-14_40_57_shellexecute-error.png" alt="2024-01-30 14_40_57_ShellExecute - ERROR.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">What am I missing here? Did I misunderstand you?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/92511</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92511</guid><dc:creator><![CDATA[Ron Tarrant 1]]></dc:creator><pubDate>Tue, 30 Jan 2024 19:44:42 GMT</pubDate></item><item><title><![CDATA[Reply to When Running Python from NPP, the Script Can&#x27;t Find Local Image Files on Tue, 30 Jan 2024 19:34:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ron-tarrant-1" aria-label="Profile: Ron-Tarrant-1">@<bdi>Ron-Tarrant-1</bdi></a> ,</p>
<p dir="auto">you don’t need to do it all in a single <code>cmd</code> call … and the <code>/K</code> option says “keep this cmd shell running”, which means you’ve actually superceded the NppExec console and jumped to a persistent <code>cmd.exe</code> environment, so until you <em>manually</em> type <code>exit</code> from that shell, you’ll be stuck in that cmd.exe shell.</p>
<p dir="auto">What you really want, if you need to execute one command that doesn’t execute straight from the NppExec script itself, is to use <code>cmd.exe /c</code>, so that cmd will return control to NppExec when it’s done, rather than keeping the cmd shell open.</p>
<p dir="auto">So what you probably want is something more like</p>
<pre><code>npp_save
cd "$(CURRENT_DIRECTORY)"
cmd.exe /c python "$(FULL_CURRENT_PATH)"
</code></pre>
<p dir="auto">… and since you changed into the file’s directory already, you can actually use <code>"$(FILE_NAME)"</code> instead of <code>"$(FULL_CURRENT_PATH)"</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/92510</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92510</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 30 Jan 2024 19:34:27 GMT</pubDate></item></channel></rss>