25

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 ?

jeff
  • 13,055
  • 29
  • 78
  • 136
  • 2
    Did you restart your machine after you made the changes? – Matthias Jun 12 '14 at 14:25
  • 4
    Restart your command line prompt – Rohit Srivastava Jun 12 '14 at 14:29
  • To address the issue of `PATH`, the following answers below help: [remove `\python.exe`](https://stackoverflow.com/a/51577329/) as entries in [`PATH` point to directories](https://en.wikipedia.org/wiki/PATH_(variable)), not files, and [remove the space character after the `;`](https://stackoverflow.com/a/49561884) (i.e. change `; ` to `;`). – metatoaster May 09 '23 at 01:55

17 Answers17

27

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.

yossim
  • 306
  • 2
  • 5
  • I restarted cmd, but not restarted the system. Let me try that. Thanks ! – jeff Jun 12 '14 at 14:36
  • 4
    The 2nd part is not only unnecessary, but invalid. Only add directories to `PATH`, and don't leave a space after the semicolon. You can also modify `PATH` in the current process. Run `set PATH=%PATH%;C:\Python34`. But it's only permanent if you modify the value in the registry. – Eryk Sun Jun 12 '14 at 21:00
  • 1
    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. – Eryk Sun Jun 12 '14 at 21:04
  • @eryksun Thanks a lot, I did not know that leaving a space after the semicolon would break it. – Borjante Sep 18 '17 at 08:07
  • 1
    For anyone else looking, `echo %PATH%` is for cmd. For powershell use `$env:Path` - which is so much more memorable, innit? #microsoft – Spectraljump Jun 17 '21 at 10:21
  • You may have to verify the %PATH% is valid. Mine looked right when I scanned over it, but when I looked closer I saw a single " character to open quotes that were never closed. Got rid of this and it worked. – icanfathom Nov 23 '21 at 20:42
  • @ErykSun As of 2022, `py` runs Python 3 by default. (You saved me hours) – Nice Books Mar 11 '22 at 18:52
24

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

Josef Ginerman
  • 1,460
  • 13
  • 24
senis000
  • 241
  • 2
  • 6
  • 5
    ugh...I knew it was something stupid like this. Kept trying to use some variant of "python" or "python3.7". Thank you for this. For the record, use "py" instead of "python" – Mike Kellogg May 20 '19 at 14:08
19

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

tatoline
  • 423
  • 6
  • 11
  • 1
    This should be the first thing to check after installing Python from a downloaded package on a newly built Windows system. The App Installer shortcut forces launching the Windows Store while attempting to run Python from CLI until the execution alias is disabled. – Jim Diroff II Feb 08 '23 at 16:03
  • If you are having problems with app execution aliases, that is **not related** to the question here. Please see [CMD opens Windows Store when I type 'python'](https://stackoverflow.com/questions/58754860) instead. – Karl Knechtel Feb 28 '23 at 03:01
  • Finally a solution that actually helped, thank you very much! – Tignite Mar 14 '23 at 10:18
  • Thank you. Even though I had added python to my path, this was preventing it from running via CMD – rbohac May 24 '23 at 17:28
  • This is EXACTLY the answer to the question above for the situation I was having. Python was in the path but NOT being found. I was getting this error but an alias was in the way. Turning off the aliases made the path work properly. The specific pair of aliases in the way were listed as Python installer aliases in my case. – Jeff Clayton Jun 10 '23 at 15:40
  • So many solutions which just amount to "Have you tried doing the thing you said you did in your post". Thanks for finding the real solution! – Kai Salmon Jul 15 '23 at 09:44
  • Wow. What an obnoxious feature. – Adam Starrh Jul 25 '23 at 21:16
  • Seriously why does this exist by default? – ogginger Aug 24 '23 at 02:41
10

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!

Arnab Roy
  • 307
  • 3
  • 8
7

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.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
uditgt
  • 139
  • 1
  • 1
  • Surprisingly, this is exactly what did the trick for me. Any idea why it is like this actually? All guides say to add the Python path to the END of `PATH` variable. – Valeria Nov 08 '22 at 10:04
  • Same for me, this worked. For me, when I called python from the command line, the windows store would pop up, which makes sense. So if the windows App store is opening when you try python, for sure try this! – Alex Jan 31 '23 at 16:51
  • This is **a different and unrelated problem**, which is properly addressed by a **different question**. The canonical is here: [CMD opens Windows Store when I type 'python'](https://stackoverflow.com/questions/58754860). – Karl Knechtel Feb 28 '23 at 02:59
5

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.

Community
  • 1
  • 1
bcorso
  • 45,608
  • 10
  • 63
  • 75
  • There's a combined limit of 1024 characters if you set a user `PATH`, which is a general limit on loading user environment variables from `HKCU\Environment`. If I just add to the system `PATH` without storing a user `PATH`, the limit is 2048 characters (before expanding the `REG_EXPAND_SZ`). It's weird that setting a user `PATH` cuts the limit in half. In a live process, I can extend this to 8192 characters, which helps if you have batch files that set up a work environment (e.g. the Windows SDK). – Eryk Sun Jun 12 '14 at 22:42
4

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;

nihal111
  • 368
  • 3
  • 9
0

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.

0

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.

Nick W
  • 877
  • 2
  • 15
  • 30
0

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%

0

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.

Manojkumar Khotele
  • 963
  • 11
  • 25
-1

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.

KCP
  • 23
  • 3
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33936021) – Juan Diego Lozano Mar 03 '23 at 13:01
-2

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.

dev ip
  • 1
-2

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.

mindmischief
  • 271
  • 1
  • 12
-2

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.

Matthew
  • 1,905
  • 3
  • 19
  • 26
-2
  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.
Mohannad A. Hassan
  • 1,650
  • 1
  • 13
  • 24
Mark S. Khalil
  • 113
  • 1
  • 4
-3

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.

maulynvia
  • 15
  • 4
  • 1
    I think this was a mistake (renaming the exe) - I ran into some strange errors after a while and then could not uninstall to reinstall python to solve. (This was fixed by running MS Fixit http://support2.microsoft.com/fixit/). Now I just have python27 identified in the path so it is the default version and then call "C:\Python34\python" with full path when I wish to start python3 – maulynvia Jan 15 '15 at 17:47