"python" not recognized as a command

PythonWindows

Python Problem Overview


I just downloaded and installed Python 2.7.2 to my laptop and I am trying to run some sample programs. My laptop is running Windows XP.

When I open a cmd window and type python I get:

> 'python' is not recognized as an internal or external command, operable program or batch file.

I am not a Windows person (mostly mainframes). However I am guessing that there is some command that I need to execute to define python as a command. Can anyone tell me what that command is?

The installer placed Python at C:\Python27\.

Python Solutions


Solution 1 - Python

You need to add the python executable path to your Window's PATH variable.

  1. From the desktop, right-click My Computer and click Properties.
  2. In the System Properties window, click on the Advanced tab.
  3. In the Advanced section, click the Environment Variables button.
  4. Highlight the Path variable in the Systems Variable section and click the Edit button.
  5. Add the path of your python executable(c:\Python27\). Each different directory is separated with a semicolon. (Note: do not put spaces between elements in the PATH. Your addition to the PATH should read ;c:\Python27 NOT ; C\Python27)
  6. Apply the changes. You might need to restart your system, though simply restarting cmd.exe should be sufficient.
  7. Launch cmd and try again. It should work.

Solution 2 - Python

This is because the Python exec are not in the search path of your operating system. In windows, start CMD. Type in

setx PATH PythonPath

where PythonPath is usually C:\Python27 or C:\Python33 or C:\Users\<Your User Name>\AppData\Local\Programs\Python\Python37 depending on your Python version. After restarting the CMD, you should get see outcomes when typing

Python --version

Solution 3 - Python

Python comes with a small utility that fixes this. From the command line run:

c:\python27\tools\scripts\win_add2path.py

Make sure you close the command window (with exit or the close button) and open it again.

Solution 4 - Python

Just another clarification for those starting out. When you add C:\PythonXX to your path, make sure there are NO SPACES between variables e.g.

This:

SomeOtherDirectory;C:\Python27

Not this:

SomeOtherDirectory; C:\Python27

That took me a good 15 minutes of headache to figure out (I'm on windows 7, might be OS dependent). Happy coding.

Solution 5 - Python

I had the same problem for a long time. I just managed to resolve it.

So, you need to select your Path, like the others said above. What I did:

Open a command window. Write set path=C:\Python24 (put the location and the version for your python). Now type python, It should work.

The annoying part with this is that you have to type it every time you open the CMD.

I tried to do the permanent one (with the changes in the Environmental variables) but for me its not working.

Solution 6 - Python

Go to Control Panel / System / "Advanced" tab / Enviromental Variables

Find variable called PATH in the lower list, and edit it. Add to the end C:\Python27

Open a new cmd window and try now.

Solution 7 - Python

You can do it in python installer: enter image description here

Solution 8 - Python

emphasis: Remember to always RESTART the CMD WINDOW after setting the PATH environmental variable for it to take effect!

Solution 9 - Python

in PowerShell enter this:

> [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", > "User")

Close PowerShell and then start it again to make sure Python now runs. If it doesn’t, restart may be required.

enter image description here

Solution 10 - Python

Further to @Udi post this is what the script tried to do, but did not work with me.

I had to the set the following in the PATH nothing else.

C:\Users\hUTBER\AppData\Local\Programs\Python\Python35
C:\Users\hUTBER\AppData\Local\Programs\Python\Python35\Scripts

Were mine and now python works in the cmd

Solution 11 - Python

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

enter image description here

Solution 12 - Python

Make sure you click on Add python.exe to path during install, and select:

> "Will be installed on local hard drive"

It fixed my problem, hope it helps...

Solution 13 - Python

Another helpful but simple solution might be restarting your computer after doing the download if Python is in the PATH variable. This has been a mistake I usually make when downloading Python onto a new machine.

After restarting my machine then Windows will often recognize Python in the PATH variable.

Solution 14 - Python

Easy. Won't need to get confused but paths and variables and what to click. Just follow my steps:

Go to the python installer. Run it. Out of the 3 options choose modify. Check py launcher. Next. Check "Add python to environment variables" Install.

Restart the cmd when finished and boom done

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDave BaxterView Question on Stackoverflow
Solution 1 - PythonPepeView Answer on Stackoverflow
Solution 2 - PythonSamView Answer on Stackoverflow
Solution 3 - PythonUdiView Answer on Stackoverflow
Solution 4 - PythonbathMarm0tView Answer on Stackoverflow
Solution 5 - PythonAlina RisteaView Answer on Stackoverflow
Solution 6 - PythonRookView Answer on Stackoverflow
Solution 7 - PythonBakos BenceView Answer on Stackoverflow
Solution 8 - PythonlodeView Answer on Stackoverflow
Solution 9 - PythonsnrView Answer on Stackoverflow
Solution 10 - PythonJamie HutberView Answer on Stackoverflow
Solution 11 - PythonJohn LoboView Answer on Stackoverflow
Solution 12 - Pythonuser235913View Answer on Stackoverflow
Solution 13 - PythonKevinView Answer on Stackoverflow
Solution 14 - PythonUrDistractionView Answer on Stackoverflow