How do I add Python to the Windows PATH?

683,831

Solution 1

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
    
  7. Test on a new terminal window or if using an integrated terminal within a text editor, close and restart your editor or the changes won't be applied.

Solution 2

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.

Solution 3

  • 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

Solution 4

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).

Share:
683,831

Related videos on Youtube

davewise
Author by

davewise

Updated on September 17, 2022

Comments

  • davewise
    davewise over 1 year

    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?

  • Michael Mrozek
    Michael Mrozek over 11 years
    @alord1689 Right-click "My Computer" on the desktop and choose "Properties"
  • MikeM
    MikeM over 6 years
    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\Pytho‌​n\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.
  • Ravindra Bawane
    Ravindra Bawane about 6 years
    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.
  • Csaba Toth
    Csaba Toth over 5 years
    Besides that it installs 3.7 into C:\Users\${username}\AppData\Local\Programs\Python\Python37 - just sayin
  • André.B
    André.B about 4 years
    Step 1 for Windows 10 is deprecated - Right-click This PC, and select Properties from the menu instead. Win + pause combo should still work but not all laptops have a labelled pause/break key.
  • no nein
    no nein almost 4 years
    I might just be dense but when i add that in there (I am using Anaconda) I still get the same error in CMD: 'python' is not recognized as an internal or external command, operable program or batch file. I put in: C:\Users\Username\Anaconda3
  • Amit Naidu
    Amit Naidu over 3 years
    Or just type "Edit env" in the start menu
  • Amit Naidu
    Amit Naidu over 3 years
    It is not the same answer because the accepted answer modifies system variables and requires administrative privileges in Windows 10.
  • wordsforthewise
    wordsforthewise over 3 years
    @AmitNaidu or just type 'env' in the start menu
  • Amit Naidu
    Amit Naidu about 3 years
    No, that will take you to the system environment variables, which requires admin rights.It is preferable to edit your user environment variables. This is sometimes the only option on work machines where you may not have superuser privileges.
  • fig
    fig almost 3 years
    The accepted answer also doesn't add the scripts folder...