Trying to run a .py file in IDLE from Notepad++
Hi guys, this is my first time on this board, and I’m not very experienced with programming yet, so this may be a dumb question.
I’m following the lessons in “Automate the Boring Stuff with Python”, and I wanted to try to write my code in Notepad++ instead of IDLE’s built-in file editor. I tried following the advice on this page “https://silentcrash.com/2016/12/run-python-script-notepad/”, but every time I hit “Run” in Notepad, I get an error window titled “ShellExecute - ERROR” that states:
"The system cannot find the file specified.
An attempt was made to execute the below command.
[location of idle.py][location of file trying to be opened]
Error Code: 2"
If you guys can help me out in any way I would be very appreciative, since Notepad++ looks like a very nice editor, and I would love to be able to open my little test programs into IDLE without any fuss.
@Travis-Vawser: welcome to the Notepad++ Community forum.
Python … “ShellExecute - ERROR”
Sounds like you’re following the same instructions as another user did last week: asked here. We started giving advice, but the user dropped out of the conversation. Hopefully, you’ll be able to stick around long enough to get your problem solved, rather than dropping out midway through. Feel free to read through that advice first; it will help you understand where I am coming from.
I do appreciate the link to the instructions you were following. I see
twothree issues with their advice:
- They want you to specify a
.pyas the “executable” file. That’s relying on the Windows
.pyassociation, and is where the “shell execute” message is coming from. (That helps explain things, which the other poster had neglected to inform us about.) Some run commands will work through their associations, but everything has to be set up “just so”. I would actually recommend being more explicit, rather than relying on the default association, especially since it’s giving you trouble as-is. More on this below.
- Their python3 example command-line had spaces in the path to the “executable” (really, to the
idle.pywrapper script), and following their directions for the python2 might also end up with spaces, depending on where your python2 installation really was.) Any time a path does have (or may have) a space, you should really enclose it in quotes.
- they show smartquotes rather than real quotes; if you copy/pasted those, that’s a likely culprit.
With that said, assume for the moment (python2 or python3) that your python executable is at
"c:\path to\python#\python#.exe"and that your
If you want to follow their advice, and rely on the Windows
.pyassociation (and assuming that the association properly handles spaces in the python path; presumably it does if you’re able to run IDLE normally), then I would suggest:
"c:\path to\python#\Lib\idlelib\idle.py" "$(FULL_CURRENT_PATH)"
(note the real quotes; note that there are quotes around each path, because there are or may be spaces)
If you want to get rid of the shell-execute interface (get rid of relying on the
"c:\path to\python#\python#.exe" "c:\path to\python#\Lib\idlelib\idle.py" "$(FULL_CURRENT_PATH)"
(I am not a command-line python expert, and the system that I’m on right now doesn’t have a python executable, so I’m not sure if python correctly cascades the remaining command-line arguments to your script. I know that
perl.exe something.pl third.plwill send
third.plas the argument to the
something.plscript in the perl world… I would assume python.exe behaves similarly, so that FULL_CURRENT_PATH will be sent to the idle.py script.)
If those don’t work, please let us know exactly what paths you wrote. (to avoid problems with smartquotes, surround any inline text with backticks (example:
`surrounded by backticks`will render as
surrounded by backticks), and use
``` big long text ```
for inserting multiline blocks of code
- They want you to specify a
Thank you for responding! I noticed that you had spaces between “c:\path to\python#\Lib\idlelib\idle.py” and “$(FULL_CURRENT_PATH)”, which I previously did not have spaces between. After putting that space in, IDLE did end up opening, BUT it didn’t runt the program from Notepad++. Instead, the IDLE window looked like this.
Instead, the IDLE window looked like this.
And if you look on the title bar of the IDLE window, you can see that it was trying to open
$(FULL_CURRENT_PATH); since the extra
Hmakes it a different (undefined) variable, Notepad++ didn’t translate it into the value of the actual
It would appear that my inexperience with coding is leaking through! Got rid of the pesky “H”, and now it works perfectly. Thank you so much for your help!
Alan Kilborn last edited by Alan Kilborn
my inexperience with coding is leaking through
Coding doesn’t have anything to do with it. It is a lack of attention to detail (in other words, spelling things correctly).
Got rid of the pesky “H”, and now it works perfectly
Glad it works for you now.
I tried to submit a comment to the posted blog entry, but it rejected my first two attempts as spam, and claimed to accept my third, though it hasn’t shown up yet.