Enroll Course

100% Online Study
Web & Video Lectures
Earn Diploma Certificate
Access to Job Openings
Access to CV Builder



Online Certification Courses

How To Add Python To The Windows PATH Variable

How to Add Python to the Windows PATH variable. 

Why Add Python To Windows PATH?

If you fail to add Python to the PATH on your Windows OS, you can't run the Python interpreter, start a virtual programming environment,  or run commands like pip install from the terminal.

That's because, when you run any non-default program from the command line, the machine looks for an executable in the current folder, or in the Windows PATH.

If it's not in the PATH variable, the terminal returns a "command not found" error. Adding to the PATH is powerful, even if you're executing a command from a created or default batch file, adding its parent execution file to the PATH variable makes it callable from the terminal as well.

How To Manually Add Python To The Windows PATH

First off, if you've not installed Python on your machine, go to the python.org website to download and install your preferred version.

Once Python is successfully installed on your PC, check if it's already added to the Windows PATH. Open up your terminal and type python, then hit the Enter key. The command might return an error that says "'python' is not recognized as an internal or external command, operable program or batch file," indicating that Python isn't added to your machine's PATH variable yet.

To execute Python programs from your command line, follow the steps highlighted below.

 Find Python's Installation Path On Your PC

To add Python to your Windows PATH, you need to get its installation path. To do that,

  1. Open up the Windows search bar and type python.exe (don't hit the Enter key).
  2. Then right-click on Python.exe that pops up in the resulting menu and select the Open file location option.
  3. In the Explorer windows that opens, click on the long directory bar to the left of the search bar.
  4. Highlight and copy the entire path text to your clipboard with Ctrl + c.
  5. Then continue with the next steps below.

Next: Add Python To PATH In User Variables

To add Python to the PATH in User variables,

Right-click on This PC, and select Properties.

Once in the properties menu, click on the Advanced system settings option.

  1. In the next window, select the Advanced tab, and select Environment Variables. 
  2. The Environment Variables menu has two distinct parts: an upper part called User variables, and a lower part named System variables. However, our focus is on the User variables in this case.
  3. Within the User variables menu, locate a variable called Path.
  4. Then paste the path you copied earlier in the Variable value option using Ctrl + v and click Ok.

However, if you can't find that variable, you might need to create it. To do that,

  1. Click on New.
  2. Next, in the Variable name form, type Path, and paste your Python path in the Variable value field.
  3. Go back to your Python installation path folder and double-click on Scripts to open that directory.
  4. Next, copy its path from the path bar at the upper part of the windows (besides the search bar), just like you did earlier for the Python installation path. 
  5. Once you've copied the Scripts path, head back to the Environment Variables.
  6. Next, select the Path variable and click on Edit. Type a semi-colon after your Python executable path and paste the Scripts path you just copied after it.
  7. Then click Ok.

Adding Python To The PATH With The System Variables Option

You can add Python to the System Variables PATH as well. Although this is just an alternative, and it's not necessary if you've added it in the Users variables already. 

To use the System Variables option,

  1. Follow the steps highlighted above for copying the Python path and its Scripts path.
  2. Then head back into the Environment Variables.
  3. Then, inside the System Variables segment, locate a variable called Path.
  4. Click on that variable and click on Edit.
  5. In the next window that comes up, click on New and paste the path you copied earlier in the opened space.
  6. Repeat that process for the Scripts path as well.
  7. Next, click Ok and close the Environment Variables window.

Add Python To Windows PATH Automatically

You can add Python to the Windows PATH automatically during installation as well. Although using this method doesn't work in all cases, you can still give it a try.

To do that, click on your installation file and check the Add Python 3.7 to PATH box. The version number will change when installing different versions of Python.

Checking that box adds Python to your Windows PATH automatically. That means you can start running Python commands via the command line immediately after installation.

Confirm That Python Is Added To Windows PATH

To see if Python is already added to the Windows PATH, open the terminal and type python --version, then hit the Enter key. If the command returns the currently installed version of Python, it means you've successfully added it to the Windows PATH. 

However, to check if you've added the Scripts directory to the Windows PATH, try to run pip install package on the terminal, replacing "package" with your preferred library. If you've installed Python 2.7.9 and above, the command installs the named package, indicating that you've successfully added Python's Scripts to the path as well.

Related Courses And Certification

Windows OS Course And Certification

Python Programming Course And Certification

Basics of Computer Science - Course and Certification

Computer Networking Course and Certification

Basics of Computer Science - Course and Certification

Corporate Training for Business Growth and Schools