简体   繁体   中英

Add “python2” path to command line on Windows 7

I've been trying to add the python2 path to command line on Windows 7.

I have tried to do it this way:

C:\>set python2 = C:\Python27\python.exe

But cmd told me that:

'python2' is not recognized as an internal or external command.

So how can I add python2 path to command line on Windows 7?

Thanks.

This answer copied from my own answer , and customized to this question.

Try following command.

set path=%path%;c:\python27

PATH is set only for the cmd.exe in which you run the above command.

To permanently set PATH:

  1. Right click My computer in the desktop.
  2. Click Advanced System Settings on the left.
  3. Click Environmental Variable .
  4. Add or Update PATH variable:
    • If it does not exist, create one, and set value as C:\\python27
    • If it exist, append ;C:\\Python27 to existing value.
  5. Restart cmd.exe. (PATH will not change for already launched cmd.exe)

UPDATE

If you want to use python2 , copy the executable.

CD C:\python27    
COPY python.exe python2.exe

Had the same problem and fixed it... I have C:\\Python27 , which i have added to my environment variables which gave me access to "python" though the CMD.. but for installing node-sass though npm, which was my problem, it continues to say that "python2" is not found. A friend the told me i could just rename name executable, which i didn't belive, but it worked :-)

The rename was from: C:\\Python27\\python.exe > C:\\Python27\\python2.exe

It works for me, even though it find it weird just renaming a file.. but then, i am not hardcore in the windows CMD.

I don't know whether it can be switched or not while keeping both python2 and python3. But while working with python2 you can remove the "python3 path" from the PATH. Cause By default in windows python3 is selected if both are installed. So you can try this to use python2. then when necessary again add the "python3 path " to the PATH

although I add Python to path variable, it appeared further, I tried with Thor A. Pedersen's answer it worked, I found another way without rename python.exe to python2.exe , just update your node config as bellow. It worked for me.

npm config set python python2.7 or npm config set python python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM