64

I want to be able to run Python commands from the Windows CMD. However, if I don't specify Python's full path for each command, I get an error saying "Python is not recognized as an internal or external command, operable program or batch file."

How do I add Python to the Windows PATH permanently?

migrated from stackoverflow.com May 19 '10 at 22:01

This question came from our site for professional and enthusiast programmers.

61

For Windows 10/8/7:

  1. Open System Properties (Right click Computer in the start menu, or use the keyboard shortcut Win+Pause)
  2. Click Advanced system settings in the sidebar.
  3. Click Environment Variables...
  4. Select PATH in the System variables section
  5. Click Edit
  6. Add Python's path to the end of the list (the paths are separated by semicolons). For example:

    C:\Windows;C:\Windows\System32;C:\Python27
    

For Windows XP:

  1. Open System Properties (Type it in the start menu, or use the keyboard shortcut Win+Pause)
  2. Switch to the Advanced tab
  3. Click Environment Variables...
  4. Select PATH in the System variables section
  5. Click Edit
  6. Add Python's path to the end of the list (the paths are separated by semicolons). For example:

    C:\Windows;C:\Windows\System32;C:\Python27
    
  • 18
    I didn't know about Win + Pause and now I feel stupid. – vitorbal May 19 '10 at 22:00
  • 3
    @vitorbal: we all have these moments, for some these key short cuts are known for a long time, for the same folks other things are relatively new. no need to feel stupid, especially not in public – akira May 20 '10 at 6:27
  • 1
    What if you're running on a VM on a laptop which has neither a windows key nor a pause key? – alord1689 Nov 1 '12 at 4:11
  • 1
    My keyboard (Lenovo W540) doesn't even have a pause key... or if it does, I can't find it. – ArtOfWarfare Aug 6 '15 at 18:45
  • 1
    The interesting thing here is where Python actually gets installed. Earlier versions would go directly to a folder off the root (C:/Python27) but now it seems the default web install places it in the user's AppData/Local here: C:\Users\{yourUserNameGoesHere}\AppData\Local\Programs\Python\Python36 I didn't check the box as Python was installing, but after adding this to the end of the path as other users have stated, it seems to work. At least, new command windows had this in the path, and python would start. Git BASH windows still used the old path and probably require a reboot. – MikeM Sep 11 '17 at 4:54
11

For anyone trying to achieve this with Python 3.3+, the Windows installer now includes an option to add python.exe to the system search path. Read more in the docs.

1

As seen in the Python documentation:

Windows has a built-in dialog for changing environment variables (following guide applies to XP classical view): Right-click the icon for your machine (usually located on your Desktop and called “My Computer”) and choose Properties there. Then, open the Advanced tab and click the Environment Variables button.

In short, your path is:

My Computer ‣ Properties ‣ Advanced ‣ Environment Variables In this dialog, you can add or modify User and System variables. To change System variables, you need non-restricted access to your machine (i.e. Administrator rights).

1
  • Click on the windows button to start a search
  • type in "system env" and click on the "edit system environment variables"
  • Now click on the advanced tab on the top
  • At the bottom click the button that says "environment variables"
  • Now on the "user variables'your user name'" box at the top of the windows click on path then edit
  • This should lead to another window where you want to click "new" and type in the commands: "C:\Python27" and "C:\Python27\scripts"
  • Python should now work on command prompt
  • This is the same answer already posted in the accepted answer. Please to not post answers unless they add helpful and unique information to the discussion. – music2myear Feb 12 '18 at 22:07
0

Right-click on My Computer, choose Properties. Then find the Environment Variables button (on Win7, it's under the Advanced tab; I forget where it is on other versions of Windows). Click that, and under System variables, edit the Path one.

protected by Ben N Jul 12 '18 at 23:24

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.