lsheng
lsheng

Reputation: 3749

Can't add Python in Windows cmd

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?

Upvotes: 1

Views: 1368

Answers (5)

ELamar
ELamar

Reputation: 114

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.

Upvotes: 0

ksvagarwal
ksvagarwal

Reputation: 9

  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

Upvotes: 1

anon582847382
anon582847382

Reputation: 20391

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.

Upvotes: 2

merlin2011
merlin2011

Reputation: 75629

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.

Upvotes: 3

elhostis
elhostis

Reputation: 1087

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

Upvotes: 0

Related Questions