简体   繁体   中英

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?

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.

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

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!

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.

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.

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; C:\\Windows\\system32; C:\\Python27; C:\\Python27\\Scripts;

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

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.

我在 Windows 10 上使用 Python 2.7 遇到了同样的问题,直到我将环境变量中的文件路径更改为文件夹路径,即C:\\Python27\\python.exe不起作用但C:\\Python27\\确实起作用。

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%

The problem might be due to the length of path. My problem has been resolved by just writing "C:\\Python27;" at the staring of the environment variable. Now my path looks like C:\\Python27;C:\\Windows\\SYSTEM32;Other_paths_etc;

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! 应用程序执行别名

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.

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.

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.

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.

  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.

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\\python 34 .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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM