Adding Python to the Path
If you're on Windows and know you have Python installed from python.org (our recommended way) but you're still getting errors like
pip : The term 'pip' is not recognized as the name of a cmdlet, function, script file, or operable program.
when trying to run a pip
or pyinstaller
command, or running python
unexpectedly opens up the Microsoft
Store, the issue is likely that your Windows Path
environment variable is improperly configured for Python. This just means Windows doesn't know how to find your Python
installation.
The Path (or PATH) environment variable is what Windows uses to locate executables needed on the command line. Whenever
you type a command name in your terminal, like python
or pip
, the terminal looks for a program of the same name in
the folders listed in the Path, so the command can be run.
The python.org Python installer provides an option to add Python to your Path automatically, although it is not checked by default so many people miss it:
But don't worry, you can have the installer add it after the fact, or add it yourself! Continue on just below to the safe method to have the installer put Python on Path for you. Or, if you want to learn a handy Windows programming skill, skip to the advanced method that explains how to edit the Path manually.
Safe method: Let the installer add Python to Path¶
The easiest and safest way to add Python to Path is by rerunning the installer. For this you will need the same
installer you used to install Python, which you can download again if needed from
python.org, or it may still be in your Downloads folder (it's a file named
something like python-3.11.0-amd64.exe
).
Once you have it, here are the steps to modify the installation to add Python to Path:
-
Run the installer by double clicking it.
-
Select "Modify". (If you don't see the "Modify/Repair/Uninstall" screen then you likely have the wrong installer.)
-
Hit "Next" to move past the "Optional Features" screen.
-
Check the "Add Python to environment variables" checkbox on the "Advanced Options" screen.
-
Hit install!
Then, after a moment, it should say "Modify was successful" and you can close the installer. Python should now be on your Path! You will need to restart any terminals or editors you have open before they detect the change.
(These steps are for the Python 3.11 and installer may differ slightly for other versions. Also, for step 1, if preferred, you can find your Python installation in the "Apps & features" Windows settings and hit "Modify" there, but will still need to locate the installer exe at step 5 if it's not already in Downloads.)
Verifying your changes¶
To check that it worked, open a fresh terminal — Command Prompt, PowerShell, an IDE-integrated terminal, Windows
Terminal, whichever you prefer, just not the
Python terminal with the >>>
prompt — and run
python -V
and then
pip -V
and you should see the versions of Python and pip that you just added to Path:
Running Get-Command python
in PowerShell, or where python
in Command Prompt, you
can see where that terminal is finding the python.exe
it would run when a python
command is given:
(where
in fact lists all the Pythons it finds, even the dummy app execution
alias one that opens the Microsoft Store.)
You can also run Python with python
(not py
as that may start a different version, see more
here), and then after >>>
in the Python REPL, run
import sys; print(sys.executable); exit();
to see that the exact executable that is currently running Python is what you expect:
Of course your username will probably not be "r", and your executable path may differ from
C:\Users\<user>\AppData\Local\Programs\Python\Python311
depending on where you chose to install Python and what
version you have. The last folder will normally be Python310
for Python 3.10, Python39
for Python 3.9, etc. But
those differences don't matter if python
and pip
and other things like pyinstaller
(if you've pip
installed it) now work for you!
Hopefully things are indeed working, however, it is possible that, due to having multiple Python versions, or other mixups, the commands are still not behaving how you expect. If so, read on to learn how to manually edit the Path. (If you already did that, open a help channel on the Python Discord server explaining everything you've tried so far, and someone will hopefully be able to help.)
Advanced Method: Manually edit the Path¶
About the Path¶
As mentioned above, the Path (often called "PATH", though it shows up as "Path") is what Windows uses to locate
executables needed on the command line. If it's misconfigured, python
and pip
commands may not work as
expected.
"Path" is the name of a Windows environment variable whose value is simply a list of paths to folders on the system. A
path is just string that locates a folder, like C:\Program Files\Git\cmd
. An environment variable is a variable (a
thing with a name and a value) that is available to the entire system, or at least to an entire user of the system.
In fact, the Windows Path is technically two environment variables, two lists of folders: a System one and a User one. But, as explained here, when actually used, the User Path is appended to the System Path, forming one long list.
So, how it works is whenever you type a command like python
into a terminal, the terminal looks for a matching
runnable file like python.exe
(or python.bat
) in each of the folders
listed in the Path, starting with the System Path (top to bottom), and then the User Path (top to bottom). It stops
searching on the first one it finds and runs that program with the command line arguments you may have given it, hence
(hopefully) running Python from an installed python.exe
.
If it can't find a runnable file that matches the command name, it spits out an error like:
foobar: The term 'foobar' is not recognized as the name of a cmdlet, function, script file, or operable program.
Or, in the case of not finding python
, it may open up the Microsoft
store.
Again, the Path lookup order is:
System Path (top to bottom) → User Path (top to bottom) → Command not found error
Adding Python to your Path¶
Here only the common case of adding Python and the Python Scripts directory to the Windows Path is detailed. However, knowing how to manually modify the Path is handy beyond just Python for whenever you need to change or debug which programs run on the command line in Windows. (The less customizable but safer method is above if you missed it.)
Follow these steps to add Python to the Path. You will need administrator privileges on your computer.
-
First, find the folder path your Python executable is in. There are a few ways to do this:
Way 1: Run
py -0p
on the command line and copy the folder path of the version you want:Way 2: Run
import sys; print(sys.executable)
in Python on your PC and copy the folder path it prints out:Way 3: Root around a bit in your
C:\Users\<user>\AppData\Local\Programs\Python
folder or wherever you installed Python to find the path to the folder that has thepython.exe
in it.I end up with
C:\Users\r\AppData\Local\Programs\Python\Python311\
(nopython.exe
at the end). Your path will of course be based on your username (my username is "r") and your version of Python, such asC:\Users\ducky\AppData\Local\Programs\Python\Python39\
if your username is "ducky" and you're using Python 3.9. Copy your path. We'll use it in steps 6 and 7. -
[This step is optional but helpful to see what's going on.] Copy the folder path from step 1 into the path bar of Windows File Explorer. In the folder you should be able to see
python.exe
, and in the Scripts subfolder, things likepip.exe
andpyinstaller.exe
(if you have it installed).These are the executables we want the command line to be able to find via the Windows Path.
-
Now, type "environment variables" in the Start menu or Start search box and open the "Edit the system environment variables" option.
-
Hit the "Environment Variables..." button.
-
Then in a new window you should see two "Path" variables, one under "User variables for <user>" and one under "System variables". Select one of them (most likely the User Path) and hit the "Edit..." button underneath it.
You should use the User Path (what the screenshots show) for the default installation of Python. In general, only put things on the System Path if they are installed for all users (e.g. in
C:\Program Files
orC:\
) and you're certain they won't overshadow anything in User Paths. Remember, the System Path takes precedence over the User Path when commands are looked up.(Don't worry if your variables or Path contents differ a bit from those shown.)
-
Now a third window opens and this is where the Path is actually edited. It shows the ordered list of the folders on the Path and you can select the entries, edit them, reorder them, make new ones, delete them and so on. (Don't delete any unless you know what you're doing!)
We want to add the Python executable path we found in step 1 as a new entry, so click "New" and paste in the path.
-
We also need to add the Python Scripts directory to the Path to have commands like
pip
andpyinstaller
work. So hit "New" and paste in the Python executable path again, and type "Scripts" after it.(It doesn't matter whether or not they have trailing backslashes.)
-
Finally, select each of the paths you just added in turn and move them to the very top of the list using the "Move Up" button. (Their relative order should not matter.)
This step may not be strictly necessary, but remember that command lookup happens in order from top to bottom. Python is often bundled with other software that may end up on the Path, so there could be another
python.exe
in one of of the other folders on the path that gets in the way. (This exact thing has happened to me when I putC:\Program Files\Inkscape\bin
on my Path, as Inkscape comes with a copy of Python.)8.5. Recall, the System Path comes before the User Path during command lookup, so to be certain you to may want to go back and check the "System variables" Path (see step 5) and carefully delete any entry that you're sure is a path to a Python executable overshadowing the one you just added. Though please, don't delete any Path entries you're aren't certain about! Just in case, for reference, here are the important looking System Path entries on my 64-bit Windows 10 PC.
-
Finish by making sure to hit "OK" on each of the thee "Edit environment variable", "Environment Variable", and "System Properties" windows, and then you're done! (If you accidentally hit Cancel the changes may not be saved.)
Python and Python Scripts should now be on your Path! You will need to restart any terminals or editors you have open before they detect the change.
At this point you can verify your changes in the same way as detailed above. Hopefully it works!
(These steps were written with Windows 10 and Python 3.11 in mind, but they should be identical or similar for Windows 11 and other recent versions of Python.)