How to fix error "'py.exe' is not recognized as an internal or external command, operable program or batch file"?

Question:

I am very new to programming and I’m trying the self-taught route, so forgive me if I am asking the wrong questions, using this site incorrectly, or breaking formatting rules. I am using a course on Udemy to learn some Python basics for Windows 10. I have reached the part in my tutorial where I am learning about executing Python commands from the Command Prompt, and I am having some issues surrounding “py.exe”. Specifically the fact that it doesn’t seem to exist on my PC.

Every time that I try anything regarding “py.exe” I get the same error from the title. I have learned through many searches that this is supposed to be a file that comes included with your Python download, and that all it really does is search the .py file for a shebang so that it can call the proper version of Python to run whatever functions you have in your code. Fine, all of that makes sense. But the system doesn’t have it anywhere. I have done a file search of the whole computer and found nothing. I saw online that Python 3.7 saves the py.exe,pyw.exe, and pyshellext.amd64.dll files in C:Windows rather than the Python download folder, and I have found pyshellext.amd64.dll there (though I don’t know what it does), but the other 2 are nowhere to be found.
My searches led me to believe that I must have messed something up on Install, so I have no uninstalled and reinstalled Python at least 4 times as administrator, and made sure that Python was added to the PATH. Nothing I do seems to make any difference, which would make sense if my download just never had py.exe or pyw.exe to begin with. However, when I call the command to test the association of .py file type, the Command Prompt seems to suggest that py.exe should be located in C:WINDOWS. But when I look I can’t find it.

C:UsersAaron>py.exe C:usersaaronmypythonscriptsHellotest.py
'py.exe' is not recognized as an internal or external command,
operable program or batch file.

C:UsersAaron>assoc .py
.py=Python.File

C:UsersAaron>ftype Python.File
Python.File="C:WINDOWSpy.exe" "%L" %*

Do I need to download some sort of stand alone version of py.exe or pyw.exe? Is there some sort of new version of either of these commands that my tutorial is just too old to account for? Has anyone else ever seen this happen?

Thank you for taking the time to read!

EDIT:
I think there is something amiss with my install process. I have done a file search from the command prompt and found nothing

C:UsersAaron> where py.exe
INFO: Could not find files for the given pattern(s)

I have tried uninstalling and reinstalling (for the 8th time) and I see the box many people have referenced that includes the py launcher with the download. It is greyed out but checked, so I assume it should be downloading with the rest of the package, but I can’t find it.

Here is a screenshot of my installer

Could the piece I have highlighted be causing me issues? It seems to imply that my system is removing the py launcher?

Asked By: Aaron Gunnin

||

Answers:

Your python executable seems not to be into the %PATH% variable of your operating system.
You have two possibilities :
Add the python executable path to the %PATH%
Explicitely launch python from the C: like C:System32python2.7python.exe or something like that depending of where it is on your system.
Have you installed python from the .exe on the official website ?

Answered By: cocool97

https://docs.python.org/2/faq/windows.html

If the python command, instead of displaying the interpreter prompt >>>, gives you a message like:

'python' is not recognized as an internal or external command, operable program or batch file.

or:

Bad command or filename

Then you need to make sure that your computer knows where to find the Python interpreter. To do this you will have to modify a setting called PATH, which is a list of directories where Windows will look for programs.

Or try a reinstall, see last comment below:

From docs.python.org/3/using/windows.html:
To install the Python Launcher for Windows for all users) […] The Python Launcher for Windows will be installed according to the option at the bottom of the first page.
And, docs.python.org/3/using/windows.html#launcher states
that the error ”py’ is not recognized as an internal or external command, operable program or batch file.’ comes from the fact that per-user installations of Python do not add the launcher to PATH unless the option was selected on installation.

Maybe a reinstall helps this time!

Answered By: Christian

I wanted to add a detailed answer for anyone that stumbles into the same situation as me in the future.

BE CAREFUL WITH YOUR INSTALL. The root of all of my issues came from doing the initial download incorrectly. If, like me, you pick a tutorial that “skips most of the computer science stuff” just know that this is not a shortcut. It is an announcing that you will have to teach the “computer science stuff” to yourself instead. It’s becoming obvious quite quickly that there is no way to skip the “computer science stuff” if you want to actually understand what you are doing.

My final solution was to uninstall anything remotely related to Python out of the entire system (as opposed to just the version that I was working in), and then reinstall the correct version while following the instructions of someone who did it correctly the first time. In retrospect it seems very obvious that trying to troubleshoot a process that Python is meant to do automatically is a way to waste time and energy, but it was also a great way to learn unnecessary lessons!

TL;DR In the beginning, don’t assume you did anything the right way. Including install (and uninstall. and reinstall. and uninstall again. and reinstall again. and uninstall again, etc.)

Answered By: Aaron Gunnin
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.