Why You Should Add Python to PATH and How

Shalewa Oseni
4 min readJun 11, 2020

--

Photo by Shahadat Rahman on Unsplash

Learning something new isn’t the easiest thing to do. You could be completely new to programming and confused about how it works, or maybe you’re an experienced programmer but new to Python. The good news is whether you are the former or latter you will find this useful. The first thing you should do is download Python. Head over to www.python.org to do this if you have not.

Now to the business of the day. After installing Python and running it, you should see a pop up like the one below. Note that I will be using Windows 10.

Adding Python to PATH via installation

If you are new to Python go ahead and tick “add Python 3.7 to PATH.” It could be “Python 3.8” or the latest version. If you plan on using multiple versions of Python on your system, then you might want to hold off on adding this downloaded version to PATH unless it is the version you want to run in your command prompt.

The Command prompt is simply an application that interprets and executes commands. One way to access the command prompt is by searching for “cmd” in the Start menu.

Opening Command Prompt

What exactly does adding Python to PATH do?

Adding Python to PATH makes it possible for you to run (use) Python from your command prompt (also known as command-line or cmd). This lets you access the Python shell from your command prompt. In simpler terms, you can run your code from the Python shell by just typing “python” in the command prompt, as shown below.

Moving from the Command Prompt to Python Shell

From the image above, I used the command prompt to execute the “python” command which resulted in moving to the Python shell. Then I ran “Hello world.”

You may have installed Python without adding it to PATH, not to worry, you can still add it. You don’t have to uninstall and reinstall it. Just follow these simple steps:

  1. Click on ‘This PC’ icon then select ‘Properties’

2. Next click on ‘Advanced System Settings’

3. Click on ‘Environment variables…’

4. Click on ‘New…’ located in User variables

5. This box should pop up

You will need to locate the relevant Python paths. The paths that you will need to get are the Python application path, which is the folder where you originally installed Python and the Python Scripts path. The Scripts folder should be located within the Python application path. You may have to reinstall Python if you can’t locate your Python path. This time take note of where it is located or store it in a way that will be easy for you to find.

This is what your Python application and Scripts path should look like:

Python Path
Python Scripts Path

For variable name, you could type a name such as ‘Path’ while for variable value, copy the full Python Path, insert a semi-colon (;) then copy the Scripts path. It should like this: C:\Program Files (x86)\Python38–32;C:\Program Files (x86)\Python38–32\Scripts

6. Click on ‘OK’ to save. Then you will see a new Python Path under the ‘User variables’ section. Ensure you click on ‘OK’ for all the pop-ups so the changes are implemented.

One last thing, launch the Command prompt, type ‘python’ now you should be able to run code with the Python Shell. THE END!

--

--