Adding Python to PATH on Windows
Solution 1
- Hold Win and press Pause.
- Click Advanced System Settings.
- Click Environment Variables.
- Append
;C:\python27
to thePath
variable. - 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:
- 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.
- NO SPACES when setting the Variables. Make sure that you are adding the
;C:\Python27
WITHOUT any spaces. (It is common to tryC:\SomeOther; C:\Python27
That space (␣) after the semicolon is not okay.) - 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. - DO NOT ADD a final backslash. Only
C:\Python27
NOTC:\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:
- Right click on "My computer"
- Click "Properties"
- Click "Advanced system settings" in the side panel
- Click "Environment Variables"
- Click the "New" below system variables
-
in name enter
pythonexe
(or anything you want) -
in value enter the path to your python (example:
C:\Python32\
) - 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
rogerklutz
Updated on December 21, 2021Comments
-
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 almost 13 yearsYeah, I've already done that. Sorry if I didn't make that clearer in the original question
-
Yossi almost 13 yearsEnsure that you don't have any spaces in your python and path variables.
-
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 over 10 yearsIn many cases, you also have to log out and back in after setting the Path variable.
-
Pavel Vlasov over 10 yearsAs 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 about 10 yearsSuffering a similar problem, had done everything but step 5... Thank you for including that.
-
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 over 9 yearsThis 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 over 9 yearsThe 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 about 9 yearsThe 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 almost 9 yearsThe command
echo $path
is only valid if you're running a bash shell under windows (e.g. MinGW). The windows command prompt command isecho %path%
-
mystrdat over 8 yearsI haven't found the trailing backlash to be problematic. Am I missing something?
-
user2099484 over 8 yearsThis 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 about 8 yearsThis solution worked for me on Win7 Pro . Tested with
echo %PATH~%
. -
Rishi almost 8 yearsThis 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 almost 7 yearsSmall 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 over 6 yearsWhat is the difference for setting environment variable for User and System?
-
infantry over 3 years%path% is your old path variable value, it is there so "C:\Python27;" will be appended to your existing path.