Adding Python to PATH on Windows

526,755

Solution 1

  1. Hold Win and press Pause.
  2. Click Advanced System Settings.
  3. Click Environment Variables.
  4. Append ;C:\python27 to the Path variable.
  5. Restart Command Prompt.

Solution 2

When setting Environmental Variables in Windows, I have gone wrong on many, many occasions. I thought I should share a few of my past mistakes here hoping that it might help someone. (These apply to all Environmental Variables, not just when setting Python Path)

Watch out for these possible mistakes:

  1. Kill and reopen your shell window: Once you make a change to the ENVIRONMENTAL Variables, you have to restart the window you are testing it on.
  2. NO SPACES when setting the Variables. Make sure that you are adding the ;C:\Python27 WITHOUT any spaces. (It is common to try C:\SomeOther; C:\Python27 That space (␣) after the semicolon is not okay.)
  3. USE A BACKWARD SLASH when spelling out your full path. You will see forward slashes when you try echo $PATH but only backward slashes have worked for me.
  4. DO NOT ADD a final backslash. Only C:\Python27 NOT C:\Python27\

Hope this helps someone.

Solution 3

Open cmd.exe with administrator privileges (right click on app). Then type:

setx path "%path%;C:\Python27;"

Remember to end with a semi-colon and don't include a trailing slash.

Solution 4

I've had a problem with this for a LONG time. I added it to my path in every way I could think of but here's what finally worked for me:

  1. Right click on "My computer"
  2. Click "Properties"
  3. Click "Advanced system settings" in the side panel
  4. Click "Environment Variables"
  5. Click the "New" below system variables
  6. in name enter pythonexe (or anything you want)
  7. in value enter the path to your python (example: C:\Python32\)
  8. Now edit the Path variable (in the system part) and add %pythonexe%; to the end of what's already there

IDK why this works but it did for me.

then try typing "python" into your command line and it should work!


Edit:

Lately I've been using this program which seems to work pretty well. There's also this one which looks pretty good too, although I've never tried it.

Solution 5

Try adding this python.bat file to System32 folder and the command line will now run python when you type in python

python.bat

@C:\Python27\python.exe %*

Source:

https://github.com/KartikTalwar/dotfiles/blob/master/bat/python.bat

Share:
526,755
rogerklutz
Author by

rogerklutz

Updated on December 21, 2021

Comments

  • rogerklutz
    rogerklutz over 2 years

    I've been trying to add the Python path to the command line on Windows, yet no matter the method I try, nothing seems to work. I've used the set command, I've tried adding it through the Edit Environment Variables prompt, etc.

    Furthermore, if I run the set command on the command line it lists this.

    python = c:\python27
    

    Yet it still doesn't recognize the Python command.

    Reading the documentation, and various other sources haven't seemed to help.

    Just to clarify further, I've appended the path of the Python executable to PATH in the Edit Environment prompt. Doesn't seem to work.

  • rogerklutz
    rogerklutz almost 13 years
    Yeah, I've already done that. Sorry if I didn't make that clearer in the original question
  • Yossi
    Yossi almost 13 years
    Ensure that you don't have any spaces in your python and path variables.
  • wassimans
    wassimans about 12 years
    @rogerklutz: Just make sure you're adding ";C:\python27" to the PATH variable that already exists, and not creating a new variable with "C:\python27" as the value.
  • dk123
    dk123 over 10 years
    In many cases, you also have to log out and back in after setting the Path variable.
  • Pavel Vlasov
    Pavel Vlasov over 10 years
    As for me, it does changes the register but none app will be affected until you manually confirm the changes via std GUI dialog. Restarting an app does not help. It looks like a kind of broadcasting is needed also.
  • ReiMasuro
    ReiMasuro about 10 years
    Suffering a similar problem, had done everything but step 5... Thank you for including that.
  • Paul Lynch
    Paul Lynch over 9 years
    +1- This lets you add to the path without needing admin privileges. However, I am not sure the %path% is needed. On my Windows 7 system, new cmd windows now have two copies of the previous paths.
  • Aur Saraf
    Aur Saraf over 9 years
    This ruined my PATH. Here is a fixed version (I also removed remove_old, which is impossible* to get right): gist.github.com/anonymous/fb5d176ab91dccbd0ebd * yes
  • grettke
    grettke over 9 years
    The reason that I chose this answer is that most of the time the PATH get's broken because of one of these 4 things. The easy part is doing it correctly, the hard part is noticing when you did it incorrectly!
  • IronManMark20
    IronManMark20 about 9 years
    The main problem with this answer is that not all computers (ex. laptops) have a <kbd>PAUSE</kbd>. I think that using kenichi's answer is cross release, and cross hardware.
  • Bruce Peterson
    Bruce Peterson almost 9 years
    The command echo $path is only valid if you're running a bash shell under windows (e.g. MinGW). The windows command prompt command is echo %path%
  • mystrdat
    mystrdat over 8 years
    I haven't found the trailing backlash to be problematic. Am I missing something?
  • user2099484
    user2099484 over 8 years
    This worked for me on 8.1 and seems easier than other approaches. A window/box opens up and asks what you want to run. Select Other and then navigate back to c:\python27 and pick the python executable (.exe). The effect appears to be permanent so you need do that only once. You will need to run win_add2path.py for every user but you don't get the box after the first time.
  • Igor
    Igor about 8 years
    This solution worked for me on Win7 Pro . Tested with echo %PATH~%.
  • Rishi
    Rishi almost 8 years
    This is what I used, because I was having trouble finding the exact path of the install. Start up the installer, hit 'Modify' and then on the Optional Features, click next, then check the box to add Python to the system path and hit Finish.
  • Right leg
    Right leg almost 7 years
    Small precision (which is what got me): once the path variable has been modified, click on OK (do not close by clicking on the X), then click again on OK on the variables window. If you don't, the changes will not be saved (not so obvious when you're used to Linux).
  • JoakimE
    JoakimE over 6 years
    What is the difference for setting environment variable for User and System?
  • infantry
    infantry over 3 years
    %path% is your old path variable value, it is there so "C:\Python27;" will be appended to your existing path.