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
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.
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...
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.
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.