1

Firstly this doesn't work:

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

Then I added .PY, .PYW in pathext so that

C:\echo %pathext%
.COM;,.EXE;.BAT;.CMD;.VBS;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW

Then I tried

C:\assco .py
File association not found for extension .py

C:\assco .pyw
File association not found for extension .pyw

Anyone could help? I don't know too much about cmd line so I just followed some steps online like How to execute Python scripts in Windows?

However it just didn't work..

My goal is to run Python in cmd line. Could anyone help?

Community
  • 1
  • 1
lsheng
  • 3,539
  • 10
  • 33
  • 43
  • probably this will be helpfull for you -> http://stackoverflow.com/questions/1934675/how-to-execute-python-scripts-in-windows – Elbard May 12 '14 at 15:18

5 Answers5

3

In Windows, Python defaults to installing in a directory called C:\Python2.x.

  1. Verify exactly what the directory is called.
  2. Go into the directory and find out where python.exe lives. Note the directory. It might be something like C:\Python2.7\bin,.
  3. Add the directory from above to your PATH. See this question for how to modify PATH in windows. The short answer is to type set PATH=%PATH%;C:\Python2.x\bin into your command prompt, using the path from part 2. If you want to set it permanently, follow the directions in Alex Thornton's answer.
Community
  • 1
  • 1
merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • Thanks, my python is installed on a server, so I just checked the server path. Sometimes when the connection lost seems that python wouldnt work. But I fixed it now by, like you said, filling the correct path. Thanks! – lsheng May 13 '14 at 03:09
2

Exact steps for adding Python to the path (on Windows 7):

  1. Control Panel -> System -> Advanced system settings
  2. Click the Environment variables... button
  3. Edit PATH and append ;C:\Python27\ to the end (substitute your Python version)
  4. Click OK. Note that changes to the PATH are only reflected in command prompts opened after the change took place.
anon582847382
  • 19,907
  • 5
  • 54
  • 57
1
  1. Right click on My computer->Properties->

  2. In the left hand corner click on advanced system settings

  3. lower right corner enviornment variables

  4. click on path and then click on the 'edit' tab

  5. Now add a semicolon at the end of the string without removing the whole string and add your path where you've installed python and save your settings

In my case the path was C:\Python27

So I added ;C:\Python 27 at the end of all the other paths

0

You have to add Python in your classpath. Like that.

 set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

More info here : https://docs.python.org/2/using/windows.html

elhostis
  • 1,067
  • 14
  • 32
0

I agree with merlin2011, except on my system (running Windows 7), Python was installed in c:\Python27 (the version I downloaded was 2.7). So navigating to that directory and typing "python" (without the quotes) invoked the program. Once you add the directory to your path, you will not need to navigate to the Python27 directory. If you installed Python 3, you might have to type "python3" at the c:\ prompt.

ELamar
  • 114
  • 11