Add “python2” path to command line on Windows 7

30,661

Solution 1

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

Solution 2

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.

Share:
30,661

Related videos on Youtube

Admin
Author by

Admin

Updated on July 17, 2022

Comments

  • Admin
    Admin almost 2 years

    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.

  • falsetru
    falsetru over 8 years
    @downvoter, How can I improve the answer? Please let me know what's wrong with the answer. I want to listen.
  • pohl
    pohl about 6 years
    I'm not the downvoter, but it appears that the question is asking how to make the python2 command appear in the PATH, but your answer shows how to get python into the PATH instead. I'm guessing the user has a script that is trying to specifically invoke Python2 in a mixed Python2/Python3 environment.
  • Julian Wise
    Julian Wise over 5 years
    This feels like it absolutely should not be the correct answer. That said with my environment variables set correctly all that required was to change the name of the executable to python2.exe and it worked! Upvote to you! Cheers
  • Banketeshvar Narayan
    Banketeshvar Narayan almost 5 years
    I just make a 2nd copy of python.exe with name python2.exe and it works for me. Thanks for you solution. Upvoted to you.
  • Schalton
    Schalton about 3 years
    2/7/21 and node-sass is still using pyhton2 smdh
  • typhon04
    typhon04 about 3 years
    I second @BanketeshvarNarayan 's comment. Seems like pip2 looks for the location of python.exe file.. so having two copies of the exe (python.exe and python2.exe) seems to work fine.
  • rook218
    rook218 almost 3 years
    @Schalton I'm hitting the same problem and can't believe that it's still an issue. All because there's a print command using python 2's syntax... If I didn't just waste enough time to get behind on this project trying to figure out the solution, I'd make a pull request myself...
  • Krushn Dayshmookh
    Krushn Dayshmookh over 2 years
    simply copying the executable solved the problem
  • adir abargil
    adir abargil about 2 years
    does this override the python for python3.* command?
  • afterxleep
    afterxleep about 2 years
    Splendid. Simple, obvious (when you realise it) and brilliant.

Related