4

I'm on Windows 10 and have Python 3.9.0 installed. The evinronment variables I have for Python are C:\Users\Zimplfy\AppData\Local\Programs\Python\Python39\ and C:\Users\Zimplfy\AppData\Local\Programs\Python\Python39\scripts\ in PATH. For some reason whenever I type py inside Command Prompt I get:

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

But when I type in python I get:

Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

Anyone have an answer to why this could be?

Thanks in advance.

5 Answers5

3

One can run the python installer again and click Modify button. enter image description here

Select py launcher checkbox. enter image description here

Then click install button and wait for the installation completes.

After all of these, py command will come back to the terminal.

krave
  • 131
2

Run in the command line:

doskey py = python

This creates an alias for the python command and then you can use py to start the python interpreter.

If you get an error regarding doskey not being recognized as an internal or external command, add C:\Windows\System32; to the PATH and run the command again. You can follow the more detailed instructions here to modify the PATH.

Yomie
  • 21
2

I do not agree with the idea of using doskey to solve this issue nor the fact that you have to tweak the registry for this.

I am just copy-pasting my answer that I answered before on the python.org forum:

This problem occurs because Windows doesn’t normally add the launcher path of the python 3.13 to the PATH variables. To solve this issue, make sure that you are running the installer on admin and add options about “adding py launcher” and “add to PATH”.

If that doesn’t work, open cmd.exe and hit where python that will display out the location of the python.exe. Navigate to the .exe’s parent folder and locate a folder called “launcher”. Inside that folder is py.exe which is what you are looking for.

Chances are that the launcher folder will exist there if you are installing from the main website. Not another source like Microsoft store.

Add the PATH of py.exe to the PATH variables.

See the forum link for image assistance.

0

you can fix it by checking

> where py

for example on my machine the output is

C:\Windows\py.exe

so if the py is missing and you have standard python installation then you need need to make sure that C:\WINDOWS is in the path by setting env path WINDIR=C:\WINDOWS

verify

echo %WINDIR%

if there is still no py.exe then reinstall python

lww
  • 101
0

The main answer is "Yomie" answer at top. the main problem is doskey output is not permanent and it will be undefined again if you close your command line. I combined this answer with this for better experience.

  • First add C:\Windows\System32 to system paths for working doskey. Then create a doskey file and add it py=python $* and save it for example as example: C:\bat\macros.doskey.

  • Then in your Start Menu search registry editor and go to HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\.

  • Right click and add Autorun.

  • Then right click on it and click on modify and write your doskey path example C:\bat\macros.doskey.

  • Then start your command line again and you will see that py is working again and is a permanent command.

Rohit Gupta
  • 5,096