- How to add Python to Windows PATH
- Method 1: Install a Recent Version of Python
- Method 2: Manually add Python to Windows Path
- How to add Python to the PATH in Windows?
- What is the Windows Path environment variable?
- Why do we want Python in the Path and should we add it?
- Python Windows path error messages
- ‘python’ is not recognized as an internal or external command, operable program or batch file.
- python : The term ‘python’ is not recognized as the name of a cmdlet, function, script file, or operable program.
- ‘pip’ is not recognized as an internal or external command, operable program or batch file.
- Adding Python to the Path automatically
- Add Python to Path – manually
- Adding PIP to the Path
How to add Python to Windows PATH
There are few ways to add Python to Windows PATH. In this guide, you’ll see two methods to add Python to Windows path:
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:
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 already exists, then click on ‘Edit…’ instead):
You should then see the New User Variable box, where you may add/edit variables:
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\Python39
(2) The Python Scripts path. The Scripts folder should be located within the Python application path. Example:
C:\Users\Ron\AppData\Local\Programs\Python\Python39\scripts
After you obtained the paths, fill the New User Variable box that you saw earlier:
- For the Variable name, type ‘Path‘
- For the Variable value, copy the full Python application path, then use semicolon (as highlighted in yellow below), and finally copy the Python Scripts path.
Variable name: Path
Variable value: C:\Users\Ron\AppData\Local\Programs\Python\Python39 ; C:\Users\Ron\AppData\Local\Programs\Python\Python39\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.
System variables
…
…
…
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:
For example, to install the Pandas package, simply type ‘pip install pandas‘ and then press ENTER:
Similarly, you may upgrade PIP by typing the following command:
python -m pip install --upgrade pip
How to add Python to the PATH in Windows?
In today’s tutorial we’ll learn how to to insert Python into the path environment variable on Windows.
What is the Windows Path environment variable?
The path is an environment variable in the Windows operating system that points to certain directories that contain specific executable files that we often use. Directories that we typically find in a Windows path are C:\Windows, C:\Windows\system32, %JAVA_HOME%\bin etc’.
Why do we want Python in the Path and should we add it?
We want Python to be set as part of the Path so we can refer to the python.exe or to utilities that are part of the Python installation in a relative manner instead of having to write the full absolute path to the executable. In plain words, the meaning of having Python (or any other executable file) in the path, is that in order to invoke Python, we would rather type python than c:\Users\dave\python3.10\python.exe in our Windows command line.
Python Windows path error messages
We typically encounter error messages when trying to run the Python interpreter from the Windows command line prompt or using the Terminal tab in the popular Python Integrated development environment. Here are a few common errors:
‘python’ is not recognized as an internal or external command, operable program or batch file.
python : The term ‘python’ is not recognized as the name of a cmdlet, function, script file, or operable program.
‘pip’ is not recognized as an internal or external command, operable program or batch file.
Same error, but this time when invoking pip. Similar error appear when invoking ipython, Mini conda / Anaconda etc’.
Similar Error in Visual Studio Code (VS) Terminal:
Adding Python to the Path automatically
The easiest way to ensure that Python is incorporated into the Path is set that accordingly when installing Python on your Windows computer. That said, even after you have already installed Python you can still use the Python installer to fix the path topic in two ways.
- First off, close any open Python files or the command prompt terminal windows.
- Then run the Python application setup executable file that matches the one installed in your computer.
- You’ll see the following dialog:
- Then select Modify, then hit Next.
- In the Advanced Options dialog mark the add Python to ENVIRONMENT variables checkbox as shown below. Then hit Install and and once done close the Setup dialog.
- Alternatively, run the Python executable file that matches the one installed in your computer.
- From the Modify Setup dialog, select Repair.
- If prompted by User Account Control hit Yes.
- The Repair Progress dialog will show the Python installation repair.
- Once done, hit Close.
The Python application and scripts folder were added to the Path.
Add Python to Path – manually
You can obviously edit your PATH environment manually .Kindly proceed as following to insert the Python directories to the path:
- On your Windows taskbar hit the magnifying glass button (search).
- In the Type here to search box, type Environment variables and hit Enter.
- The System Properties dialog will open up.
- In the bottom hit the Environment Variables button.
- In the System Variables section, highlight the Path entry.
- Hit Edit.
- Now, hit New.
- Add the absolute path to your Python.exe file. For example: C:\Python\Python3.10
- Now hit New again.
- Add the absolute path to your Python Scripts library.For example: C:\Python\Python3.10\Scripts
- Your dialog should look as following:
- Hit OK.
- Close the Environment Variables and System Properties dialogs.
- Restart your Python IDE or Command Prompt and invoke your Python application using the relative path as shown below:
- You are all set!
Adding PIP to the Path
The Python Package Manager utility PIP is accessible as an executable (exe) file right in your Python Scripts folder typically at \Scripts.
If you path is not set correctly you will get the following error when trying to install a package or to update PIP:
You can easily solve the error by manually setting the Windows path or re-installing Python as shown in the sections above.