I thought this would be easy, but I've been struggling for a while.

I have a Python script on my Windows machine called "myscript.py". I have it in a folder that's on my PATH, and I've added the ".py" extension to the PATHEXT environment variable, so I can run my script from a command prompt by just doing "myscript" (instead of typing "myscript.py"). This is working fine.

However, I cannot seem to get the same behavior when launching my script from the "Run" prompt (Windows-R). If I type "myscript.py" it works fine, but just doing "myscript" doesn't - I get the Windows cannot find 'myscript'... error message.

I would have assumed that the "Run" prompt simply doesn't recognize the PATHEXT variable, but other types of programs seem to work - I can run .bat (Windows batch scripts) and .exe (Windows executables) from the Run prompt without any extension needed.

Why doesn't running my Python script without an extension work from the Run prompt?


Doesn't really answer my question of why, but I did find a satisfactory workaround: I created a shortcut (right click on a blank area in a Windows Explorer window -> New -> Shortcut) and set the target of the shortcut to be my script. Once that shortcut is in a folder that's on my path, I can call my script with just the name of the shortcut (without any extension). This allows command line parameters to be passed to the Python script with no further modification.

Another alternative was provided by Anaksunaman - create a .bat/batch script wrapper around the script. This works fine unless your Python script needs to take params, in which case it will require more effort to pass along the parameters.

  • +1 for enabling simple parameters with a shortcut. – Anaksunaman Jul 2 '15 at 6:08

Not an answer, and you likely already thought of this as a solution so this is really for others, but using a one line .bat file to call the python script works fine. And you can, of course, name the bat file "myscript.bat" and it will work without the .bat extension.

  • I had thought of that, but my Python script takes arguments/command line params, and I don't really want to have to write batch to pass any arguments along to it. I did find a way to do it though - see my answer! – Isaac Dontje Lindell Jun 30 '15 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.