28

I recently installed Python 3.6.3 on my device. When I type python in my cmd window, it gives me this error. I do have the PATH in the environment variables. Path Lists. This should normally fix it, but python is still not recognized.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rishabh Mandayam
  • 425
  • 1
  • 4
  • 14

10 Answers10

60

I had the same problem, due to a stupid decision from Microsoft.

I had another line in my system path variable: C:\Users\MyUserName\AppData\Local\Microsoft\WindowsApps

And Windows 10 put a python.exe file there that only redirected me to the Python page of the Microsoft Store:

Enter image description here

Since this line was above my true Python path, typing python in the cmd prompt opened the Microsoft Store...

Solution:

Type App execution aliases in the Windows 10 search bar, and then uncheck the aliases for python.exe and python3.exe. More information is here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
obchardon
  • 10,614
  • 1
  • 17
  • 33
  • 1
    Just tested the alias settings - no effect in Win11 Pro 22000.708 - gets forcefully re-enabled the same nanosecond you turn it off (both python.exe and python3.exe, but not any others). Works on Win10 Pro without issue, even without Python installed at all. – Tadas S May 28 '22 at 12:12
  • My exact same problem. I was going nuts trying to figure it out, thanks for posting it. Note, for me only this worked, not changing path priorities or moving paths around as others have suggested. – Andrew Holmgren Jun 10 '22 at 14:19
  • 1
    @afk5min I had the same problem on Win10. Turns out you need to close all the apps and programs that use Python. For me it was PyCharm. After that, re-enabling went away – George Zorikov Mar 03 '23 at 18:14
39

The path to the Python executable needs to be in the System PATH variable. Note this is not the User PATH variable.

The OP had Python 3.6.3 installed in C:\Python\Python36-32, however a common default location for installation is in the users AppData\Local\Programs\ folder. This post will assume a Python 3.10 installation in this location. Please adjust as needed for your current Python version and path.

You can confirm the path from the command prompt by checking the Python executable directly from the folder.

cd %LOCALAPPDATA%\Programs\Python\Python310
python --version

This should print the Python interpreter version. For example, Python 3.10.4.

Add the following entries to the System PATH:

  • %LOCALAPPDATA%\Programs\Python\Python310 for the python executable
  • %LOCALAPPDATA%\Programs\Python\Python310\Scripts for tools such as pip

After adding the path to the System PATH variable, make sure you close and reopen any command prompts, so they use the updated PATH.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • Thank You. How do you change the path from USER to System? – Rishabh Mandayam Nov 30 '17 at 14:42
  • 5
    In your screenshot, you see an `Edit environment variable` window. Behind that in the screenshot is the `Environment Variables` window which is divided into two sections. The top section is the `User` section. The bottom section is the `System` section. Edit the `PATH` variable in the `System` section. – Brian M. Sheldon Dec 07 '17 at 17:25
11

If it is still not working, as mentioned in the previous answers, then simply move up the path, as shown in the screenshot.

Image here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Parth Developer
  • 1,371
  • 1
  • 13
  • 30
3

You get this error, because the python.exe path has not been added to the System environment variable. To do that, simply:

  1. go to the path C:\Users\%Username%\AppData\Local\Programs\Python\Python37-32 which contains python.exe

  2. copy the path and open System environment variables and in the variable section look for variable called Path. If not, create a new variable with Variable Name as Path and value as the copied path

    Enter image description here

  3. Once you do that, close the window and simply open cmd. Type python and you should get something like this:

    Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
3

If you are trying to install the new Python version, python-3.9.6, then click the checkbox of Add Python 3.9 to PATH

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John Lobo
  • 14,355
  • 2
  • 10
  • 20
3

This happens because the path doesn't exist in environment variables.

To fix this:

  1. Rerun the installer
  2. Choose Modify
  3. In optional feature click "Next"
  4. In advanced option tick the "Add Python to environment variables"
  5. Install
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

All the answers on Stack Overflow_ about it were obsolete, so I decided to add this. The path variable that needs to be added is,

C:\Users\Username\AppData\Local\Programs\Python\Python36-32

Note that everyone may have a different Username.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

If you are working with the command prompt and if you are facing the issue even after adding the Python path to system variable PATH:

Remember to restart the command prompt (cmde.exe).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mehran
  • 149
  • 2
  • 3
1

I too was struggling with this issue, and everything was configured correctly. I installed and setup my system path variables as one would. And everything was fine. Then upon reboot windows would not recognize 'python' as a command as if it were unaware of the path variable. Double checked to confirm everything was still setup correctly (it was).

It only started to work again after I manually browsed to the directory in which python.exe existed, and ran 'python'. After that windows seemed to recognize my path variable and I could call 'python' from where ever need be. Very odd. Figured I'd share in case someone else runs into this.

whitwhoa
  • 2,389
  • 4
  • 30
  • 61
0

For Python 3.6, there are actually two path entries. Also, it's best to use the %USERPROFILE% rather than hard coding it.

%USERPROFILE%\AppData\Local\Programs\Python\Python36 %USERPROFILE%\AppData\Local\Programs\Python\Python36\Scripts

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    %USERPROFILE% only applies if that's where you are installing. This would not work for custom paths. The OP had python installed in c:\Python\Python36-32 – Brian M. Sheldon May 27 '18 at 17:27
  • Guys I still cannot get this to install on my new W10 Pro -- will recognize a (broken) pip, not python. I hate Windows. – Zach Oakes Nov 04 '19 at 17:40