I've solved the issue and am posting to save others from my hours of pain.
On Windows 10,
Python is installed in C:\Python
and added to Environment Variables, but will not properly run programs.
Typing python myscript.py
in CMD does not run the program but does not produce any errors.
Typing C:\Python\python.exe myscript.py
correctly runs the code.
Navigate to C:\Users\Username\AppData\Local\Microsoft\WindowsApps\python.exe
in CMD and type del /f python.exe
.
The file located at C:\Users\MyUsername\AppData\Local\Microsoft\WindowsApps\python.exe
is viewed before the Environment Variables in PATH
. This file just opens the download page for Python in Edge.
You need to delete this file or rename it, but the items in this folder are protected by Microsoft. You get Error 0x80070780
if you try to delete this file with file explorer. In order to delete it you need to navigate to the folder in CMD with administrator privileges and type the above to remove this file.
I hope this helps someone.
While the solution I originally posted seems to work for people. I would recommend the solution posted by Max:
https://stackoverflow.com/a/65520328/9407750
The “Python is not recognized as an internal or external command” error is encountered in the command prompt of Windows. The error is caused when Python's executable file is not found in an environment variable as a result of the Python command in the Windows command prompt.
When you installed Python, you didn't check the box to add it to your PATH , which is why it isn't there. In general, it's best to use the Windows Python Launcher, py.exe anyway, so this is no big deal. Just use py for launching consistently, and stuff will just work.
The root cause is that there is "MS made" python.exe in a folder listed in the PATH variable. This folder is %USERPROFILE%\AppData\Local\Microsoft\WindowsApps . Just make sure your python installation path is listed in the PATH above the WindowsApps , that's all.
Just noticed there's an additional python executable in the windowsApp folder too when running where python
.
To remove those you can do it in the App execution aliases
in windows setting and uncheck the python aliases.
Solution from original poster; tested and worked on my system
Solution
In C:\Users\*Username*\AppData\Local\Microsoft\WindowsApps
delete python.exe
. However, because these files are protected, chances are you will get an error message when trying to delete the file. In that case, you either have to use your administrator account to delete python.exe
, or you call a cmd-window with administrator privileges and force delete ''''rm -f C:\Users*Username*\AppData\Local\Microsoft\WindowsApps\python.exe''''
About the solution
python.exe
is not the python - executable one would believe it to be, but invokes the download page for python to be opened in the Edge browser or the Microsoft App Store. The question of "who would come up with such a sadistic thing" and "why?." shall remain unanswered at this point. Fact is that calling python executes this faux- python.exe
before the PATH Environment Variables are invoked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With