2

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:\Users\Aaron>py.exe C:\users\aaron\mypythonscripts\Hellotest.py
'py.exe' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Aaron>assoc .py
.py=Python.File

C:\Users\Aaron>ftype Python.File
Python.File="C:\WINDOWS\py.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:\Users\Aaron> 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?

Aaron Gunnin
  • 33
  • 1
  • 1
  • 5
  • Shouldn't it just be `python C:\users\aaron\mypythonscripts\Hellotest.py`? – Buckeye14Guy Aug 06 '19 at 21:38
  • I think you should be able to simply run `py` from the command prompt – ForceBru Aug 06 '19 at 21:38
  • @Buckeye14Guy yes that gets it to work, but my issue is not with running Python from that command. My Command Prompt launches Python no problem, I just can't get it to recognize what py.exe should do. My tutorial is pretty clear that ```py.exe``` should be used here, but maybe it is just an old video? @ForceBru You are right I *should* be able to but it doesn't work to call Python either. I can only use "Python" to call Python – Aaron Gunnin Aug 06 '19 at 22:34
  • did you install using Microsoft store? https://docs.python.org/3/using/windows.html#known-issues – Buckeye14Guy Aug 07 '19 at 00:42
  • The py launcher is an optional feature listed on the first page of the installer. If you select the option to install it for all users, it will be installed to `"%SystemRoot%"` (i.e. "C:\Windows"). Otherwise it gets installed to `"%LocalAppData%\Programs\Python\PyLauncher"`, and this directory gets added to the per-user `PATH`. – Eryk Sun Aug 07 '19 at 16:12
  • @eryksun when I do a file search for ```py.exe``` the system can't find it anywhere. Could it be missing from my install? ```C:\Users\Aaron> where py.exe INFO: Could not find files for the given pattern(s).``` – Aaron Gunnin Aug 07 '19 at 17:36
  • Maybe the launcher wasn't installed. When you modify the install, does the initial page report the launcher is installed for all users? You shouldn't be able to change it from this dialog, either way; that's intentional. If it's supposedly installed, then something is wrong. Go to the control panel's programs and features dialog to uninstall "Python Launcher". Then reinstall Python and make sure the option is selected to install the launcher for all users. Run the installer elevated via "run as administrator" to ensure there's no technical problem when elevating to install for all users. – Eryk Sun Aug 07 '19 at 18:10
  • @eryksun thank you for your patient help through this. after going into my settings, I found that there was a damaged 32-bit version of Python that I must have incorrectly downloaded and was causing the 64-bit installer to skip the py launcher part. I completely uninstalled everything even remotely related to Python and then started the 64-bit installer from the beginning again per your suggestions, and this time I have no problems. THANK YOU!! this has been bugging me for the better part of 2 weeks. – Aaron Gunnin Aug 07 '19 at 18:34
  • Not a duplicate; `py.exe` is placed in a path that is already included in PATH by default, *deliberately to avoid* the need to worry about adding to PATH. If `python` is not found in the path, that's because `py` is being used to manage finding a Python installation. If `py` is not found, it's because it **wasn't installed**. – Karl Knechtel Sep 22 '22 at 00:40

3 Answers3

1

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:\System32\python2.7\python.exe or something like that depending of where it is on your system.
Have you installed python from the .exe on the official website ?

cocool97
  • 1,201
  • 1
  • 10
  • 22
  • Yes I installed python from the 64bit executable link on the official website. I have done it several times actually lol. My problem seems to be more than this because when I call Python by itself I don't get an error. It is explicitly when I try to use ```py.exe``` or ```py``` to call python. See below: ```C:\Users\Aaron>Python Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.``` – Aaron Gunnin Aug 06 '19 at 22:21
  • What should a proper %PATH% look like? Should it be a user variable or a system variable? – Aaron Gunnin Aug 06 '19 at 22:30
1

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.)

Aaron Gunnin
  • 33
  • 1
  • 1
  • 5
  • 1
    To everyone out there who experience this problem. DO NOT UNINSTALL Python. Go to C:\Windows\py.exe and press Ctrl-X to cut the app and paste it in your Python folder that is in C:\Users\your path...\. Do the same with pyw.exe. Now when you open terminal from any root or directory and type py or py.exe it will start Python console. – Daniel Dec 16 '20 at 12:59
0

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!

Christian
  • 4,902
  • 4
  • 24
  • 42
  • When I call "Python" it looks like this: ```C:\Users\Aaron>Python Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.``` So I think that is working correctly, but thank you. My problem seems to stem from trying to use "py.exe" explicitly – Aaron Gunnin Aug 06 '19 at 22:25
  • Isn't py.exe the same as Python? At least my system shows the same console (Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32... independent from the command py.exe or python. – Christian Aug 06 '19 at 23:03
  • Add "C:\WINDOWS\py.exe" to your path. – Christian Aug 06 '19 at 23:04
  • See here about the difference: https://stackoverflow.com/questions/50896496/what-is-the-difference-between-py-and-python-in-the-terminal – Christian Aug 06 '19 at 23:06
  • I tried adding that to my path, but it didn't do anything. It seems that the system doesn't have the 'py.exe' file anywhere. – Aaron Gunnin Aug 07 '19 at 17:38
  • From https://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, https://docs.python.org/3/using/windows.html#launcher tells me 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! – Christian Aug 07 '19 at 18:45
  • Thanks for your help! You were right, It was related to the install. I had a damaged 32-bit version of Python in my system that was triggering my executable installer to think that the py launcher was already added, except the py launcher that was added was damaged. By repairing the 32-bit version and then uninstalling it, I could reinstall the 64-bit version properly and it put py.exe in the expected place. again, THANK YOU!! – Aaron Gunnin Aug 07 '19 at 18:51
  • Cool. Nice catch. Updated my answer to reflect the comments. I think you could accept my answer with this latest finding / comment. – Christian Aug 07 '19 at 23:35