Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"python" not recognized as a command

Tags:

python

windows

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

like image 787
Dave Baxter Avatar asked Aug 14 '11 01:08

Dave Baxter


People also ask

How do I enable Python in CMD?

To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!


2 Answers

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.
like image 107
Pepe Avatar answered Oct 14 '22 16:10

Pepe


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 
like image 45
Sam Avatar answered Oct 14 '22 16:10

Sam