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\
.
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
You need to add the python executable path to your Window's PATH variable.
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
)cmd.exe
should be sufficient.emphasis: Remember to always RESTART the CMD WINDOW after setting the PATH environmental variable for it to take effect!
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.
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
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.
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.
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.
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
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.
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...
Source: Stackoverflow.com