Python -- "py" works, but "python" doesn't

Problem

In some computers,  "py" works, but "python" doesn't, such as

py works, but python doesn't

Reason 

We may run the where command to find the location where either py or Python is installed:

py works, but python doesn't

You can see that Python is installed, but when you run the command: Python you cannot reach it while you can reach py. The reason is the command python does not set up the environment PATH correctly, while py does because py is itself located in C:\Windows that is always part of the PATH, which is why you found it. On the other hand, when you installed Python; you didn't check the box to add it to your PATH, which is why it isn't there.

Let us see the detailed reason when we make the fixes.

Fix 1

This is a simple fix by reinstalling Python:

Control Panel => Program => Right Click Python => Change:

py works, but python doesn't

Click Modify:

py works, but python doesn't

You will see: py launcher is installed by default, Click Next:

py works, but python doesn't

In Advanced Options, Choose Add Python to environment variables:

py works, but python doesn't

Click Install => done.

Because Add Python to environment variables is optional, so if you did not choose it, the command PATH will not be set up properly. Why we forgot to choose this option? Actually, in my experience, Python may not be installed by us on purpose but is associated with some other applications, such as Visual Studio. In the case of Visual Studio installation, 

py works, but python doesn't

We can choose Python to be installed, but we will not have a chance to choose the detailed option, such as setting up the environment PATH.

Fix 2

Because the issue is due to the environment PATH not setup well, we can simply use the doskey command to make the Python environment PATH the same as py; we show this by phthon2 as a command:

py works, but python doesn't

We can see both python2 and py runs the Python app.

Fix 3

We can setup the environment PATH variable through the System Properties => Advanced Tab

py works, but python doesn't

Click Environment Variables:

py works, but python doesn't

Choose PATH variable => Edit:

py works, but python doesn't

Add 2 new paths 'C:\Python39' and 'C:\Python39\scripts' due to

py works, but python doesn't

How to open System Properties

py works, but python doesn't

One Step --- the easiest way:

py works, but python doesn't

This will open the System Properties Window directly.

Two Steps:

Open Settings => System => About for Windows 10

py works, but python doesn't

Open Settings: for Windows 11

py works, but python doesn't

Or we can get there by:

py works, but python doesn't

Windows 10 only

py works, but python doesn't

Both Windows 10 and 11

References:

Similar Articles