jeff
jeff

Reputation: 13673

python not recognized in Windows CMD even after adding to PATH

I'm trying to -learn to write and- run Python scripts on my Windows 7 64 bit machine. I installed Python in C:/Python34, and I added this to my Windows' PATH variable :

C:\Python34; C:\Python34\python.exe

(the second one is probably meaningless but I tried) and still I get this error in Windows command line :

C:\Users\me>python test.py
'python' is not recognized as an internal or external command,
operable program or batch file.

So how do I truly install Python on my Windows x64 machine ?

Upvotes: 31

Views: 113717

Answers (17)

KCP
KCP

Reputation: 33

If you run into this issue like I just did, save yourself some time and reboot your entire computer, not just your terminal. This fixed it instantly for me.

Upvotes: -1

tatoline
tatoline

Reputation: 875

I did everything:

  • Added Python to PATH
  • Uninstall all the Pythons - Both from downloaded python.org and Microsoft Store and reinstall from python.org
  • Change the order of PATH
  • Deleted %USERPROFILE%\AppData\Local\Microsoft\WindowsApps from PATH

But nothing worked. What worked for me was: Settings > Application > App execution aliases. Then disable all the Pyhtons from here and it worked! App execution aliases

Upvotes: 62

uditgt
uditgt

Reputation: 189

It wasn't working for me even after adding the path. What finally did the trick, was changing the order of listed paths in the PATH variable. I moved %USERPROFILE%\AppData\Local\Microsoft\WindowsApps down vs. having it the first path listed there.

Upvotes: 10

Manojkumar Khotele
Manojkumar Khotele

Reputation: 1019

I was facing similar porblem. What helped me is where command.

C:\WINDOWS\system32>where python C:\Users\xxxxxxx\AppData\Local\Microsoft\WindowsApps\python.exe C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_86\python.exe

On updating PATH variable to point to only one desired directory (basically I removed %USERPROFILE%\AppData\Local\Microsoft\WindowsApps from PATH) fixed my problem.

Upvotes: 0

Mark S. Khalil
Mark S. Khalil

Reputation: 157

  1. Uninstall python and pyqt
  2. Then go to pyqt setup and open installation but don't install. You will see a message box saying something like pyqt version built with python version 32bit/64bit.
  3. Then see python version bit and download that version from python.org from all release menu.
  4. Then first install python and then install pyqt. It will work like butter.

Upvotes: -2

Manikanta Vasupalli
Manikanta Vasupalli

Reputation: 29

I have faced same problem even though my path contains 400 characters. Try to update the path from the command line(Run as administrator)

Command to update path: setx path "%path%;c:\examplePath"

After this command I could see that paths that I configured earlier in environment variables got updated and working.

To check the configured paths: echo %PATH%

Upvotes: 0

Creepy Creature
Creepy Creature

Reputation: 1

Same thing was happening with me when i was trying to open the python immediately with CMD.

Then I kept my in sleep mode and started CMD using these Key Windows_key+R, typed cmd and OK. Then the package of python worked perfectly.

Upvotes: -2

mindmischief
mindmischief

Reputation: 271

I tried it multiple times with the default installer option, the first one, (Python 3.7.3) with both 'add to environment variable' and 'all users' checked, though the latter was greyed out and couldn't be unchecked.

It failed to work for other users except for the user I installed it under until I uninstalled it and chose "Custom Install". It then clearly showed the install path being in the C:\Program Files\Python37 directory when it was failing to install it there the other way even though the 'All Users' option was checked.

Upvotes: -2

dev ip
dev ip

Reputation: 1

For me, installing the 'Windows x86-64 executable installer' from the official python portal did the trick.

Python interpreter was not initially recognized, while i had installed 32 bit python. Uninstalled python 32 bit and installed 64 bit.

So, if you are on a x-64 processor, install 64bit python.

Upvotes: -2

Nick W
Nick W

Reputation: 917

I had the same issue with Python 2.7 on Windows 10 until I changed the file path in Enviroment Variables to the folder path, ie C:\Python27\python.exe didn't work but C:\Python27\ did work.

Upvotes: 1

senis000
senis000

Reputation: 251

I had the same problem: python not being recognized, with python in the path which was was not truncated.

Following the comment of eryksun in yossim's answer:

Also, if you installed for all users you should have %SystemRoot%\py.exe, which >is typically C:\Windows\py.exe. So without setting Python's directory in PATH >you can simply run py to start Python; if 2.x is installed use py -3 since >Python 2 is the default. – eryksun

I tried to use py instead of python and it worked. Meaning: python setup.py build -> does NOT work. py setup.py build -> does work. Hope it helps

Upvotes: 25

Arnab Roy
Arnab Roy

Reputation: 317

I was also having the same problem.

Turns out the path I added included '..\python.exe' at the end, which as turns out was not required. I only needed to add the directory in which 'python.exe' is in (which in my case is the Anaconda's distribution directory in Users folder), similar to what we do when installing JDK in our system's PATH variable.

Hope it helps!

Upvotes: 11

nihal111
nihal111

Reputation: 388

Also, make sure to leave no spaces after the semi-colon.

For example, this didn't work for me: C:\Windows\system32; C:\Python27; C:\Python27\Scripts;

But, this did: C:\Windows\system32;C:\Python27;C:\Python27\Scripts;

Upvotes: 5

David Schilpp
David Schilpp

Reputation: 73

I'm late to the game here, but I'd like to share my solution for future users. The previous answers were on the right track, but if you do not open the CMD as an administrator, then you will be thrown that same error. I know this seems trivial and obvious, but after spending the past 8 hours programming before attempting to install Django for the first time, you might be surprised at the stupid mistakes you might make.

Upvotes: 0

maulynvia
maulynvia

Reputation: 15

I spent sometime checking and rechecking the path and restarting to no avail.

The only thing that worked for me was to rename the executable C:\Python34\python.exe to C:\Python34\python34.exe. This way, calling typing python34 at the command line now works.

On windows it seems that when calling 'python', the system finds C:\Python27 in the path before it finds C:\Python34

I'm not sure if this is the right way to do this, seems like a hack, but it seems to work OK.

Upvotes: -3

bcorso
bcorso

Reputation: 47166

Environment PATH Length Limitation is 1024 characters

If restarting your cmd window does not work you might have reached the character limit for PATH, which is a surprisingly short 1024 characters.

Note that the user interface will happily allows you to define a PATH that is way longer than 1024, and will just truncate anything longer than this. Use

echo %PATH%

in your cmd window to see if the PATH being truncated.

Solution

Unfortunately, there is no good way to fix this besides removing something else from your PATH.


NOTE: Your PATH = SYSTEM_PATH + USER_PATH, so you need to make sure the combined is < 1024.

Upvotes: 5

yossim
yossim

Reputation: 316

This might be trivial, but have you tried closing your command line window and opening a new one? This is supposed to reload all the environment variables. Try typing

echo %PATH%

into the command prompt and see if you can find your Python directory there.

Also, the second part of your addition to the PATH environment variable is indeed unnecessary.

Upvotes: 28

Related Questions