There are few ways to add Python to Windows PATH.
In this short guide, you’ll see two methods to add Python to Windows path:
- Via the installation of a recent version of Python
- Manual entry of the paths
Method 1: Install a Recent Version of Python
You can easily add Python to Windows path by downloading a recent version of Python, and then checking the box to Add Python to PATH at the bottom of the setup screen:
Add Python to PATH
Finish the installation, and you should be good to go.
Alternatively, you may manually add the paths into the Environment variables.
Method 2: Manually add Python to Windows Path
If you wish to stick with the previous version of Python, you may apply the steps below to manually add Python to Windows path.
First, navigate to the Windows Environment Variables screen (where you can add/edit your paths):
- Press the Windows Key + R on your keyboard in order to open the Run dialog box
- Type sysdm.cpl to open the System Properties
- Go to the Advanced tab and then click on the ‘Environment Variables…‘
That should take you to the Environment Variables screen, where you can add/edit your paths.
Under the User variables box, click on ‘New…‘ to add the ‘Path’ variable (note that if your ‘Path’ variable is already there, then click on ‘Edit…’ instead):
OneDrive
TEMP
TMP
New… Edit…
You should then see the New User Variable box, where you can add/edit variables:
Variable value:
Before you type any values, you’ll need to locate the relevant Python paths. The paths that you’ll need to get are:
(1) The Python application path, which is the folder where you originally installed Python. You can find the Python application path by following these steps:
- Type “Python” in the Windows Search Bar
- Right-click on the Python App, and then select “Open file location“
- Right-click again on the Python shortcut, and then select “Open file location“
Here is an example of a Python application path:
C:\Users\Ron\AppData\Local\Programs\Python\Python311
(2) The Python Scripts path. The Scripts folder should be located within the Python application path.
For example:
C:\Users\Ron\AppData\Local\Programs\Python\Python311\Scripts
After you obtained those paths, fill the New User Variable box that you saw earlier:
- For the Variable name, type ‘Path‘
- For the Variable value, paste the full Python application path, then add semicolon (as highlighted in yellow below), and finally paste the Python Scripts path.
For our example:
Variable value: C:\Users\Ron\AppData\Local\Programs\Python\Python311;C:\Users\Ron\AppData\Local\Programs\Python\Python311\Scripts
Press ‘OK‘ and you would then see your new Python Path under the ‘User variables‘ section. Don’t forget to press ‘OK‘ again so that the changes will get implemented.
OneDrive
Path C:\Users\Ron\AppData\Local\Programs\Python\Python311;C:\Users\…
TEMP
TMP
New… Edit…
System variables
…
…
…
OK Cancel
You just added Python to the Windows Path.
You should be able to install Python packages easily, by opening the Windows Command Prompt and then typing:
pip install package_name
For example, to install the Pandas package, simply type ‘pip install pandas‘ and then press ENTER:
pip install pandas
Similarly, you may upgrade PIP by typing the following command:
python -m pip install --upgrade pip