Let’s say you receive an error message from Git Bash.
bash: pip: command not found
What Is a Pip Command Not Found Error?
And an error message from DOS command line.
'pip' is not recognized as an internal or external command, operable program or batch file.
What do you do?
How to Fix Pip Command Not Found
If you’ve just installed Python, you may want to rerun your Python installer and make sure you check the box “Add Python 3.6 to PATH.”
If not, don’t worry. You can add Python and the pip directory to the PATH in a bit. Next, check here for
Note that you can’t copy and paste that line. You will need to fill in your actual username in that path.
If you do find “pip 3,” you are in luck. It should look something like the image below.
If you’re navigating on Windows, you can easily get to the AppData folder by typing the
%appdata% macro into the path bar in a Windows File Explorer (formerly Windows Explorer) window.
If you can’t find the
pip3.exe, it might not be installed. So, the first thing you should do is check to see that you did install pip. Run your Windows Python installer again and check the optional features page to ensure you marked the “pip” box. It’s easy to pass over these little things, and you may have missed it the first time through.
First, check that you’ve got the “pip” checkbox marked.
Add Python to environment variables so that the Scripts folder with
pip3.exe in it can be found. Then make sure that you’ve checked the box for adding Python to environment variables.
How to Install Pip on the Command Line
If you don’t want to run your Python installer again, you can just install pip on the command line.
It is also quite possible that you may have skipped over this warning right after summoning Python from the command line or after installation.
WARNING: The scripts pip.exe, pip3.6.exe and pip3.exe are installed in 'C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
It’s easy to miss, and I think developers get into the habit of ignoring warnings like this because code often compiles with thousands of compiler warnings.
Now, let’s edit your path. Start by searching for “environment” in your Windows search tab.
Then select, “Edit the system environment variables.”You will see a window like this below.
Click the button the green arrow is pointing to labeled “Environment Variables.”
You will then have a choice. You can either edit the user path or the system path.
I usually edit the system path and have never run into issues. However, I suspect that the safer thing to do, the more “principle-of-least-privilege” thing to do, would be to edit the user path. That way only the user who needs pip access will have it. It’s up to you, but I typically never have more than one user on my machine. However, many workplaces do.
From there, you’ll want to copy the path we discussed earlier.
Make sure you use your actual username in the place of
YOUR_USERNAME. Remember, you can’t just copy paste it. While you’re here, it’s also not a bad idea to add Python to your path. So, add this folder, too. It’s just one level up:
If you can’t open the path in File Explorer, it’s not a real path.
Once you’ve pasted in the new path to the end of the path system environment variable, you can click OK to close the window.
Next you need to restart the terminal, and type in “pip” to check your work. If it works, you should see the help output in the terminal. It should look something like the image below.
If you don’t see it, you should go back to your path environment variable and make sure it is correct. Watch out for spaces in the wrong place, extra characters, etc.
The example path I gave you is on the C:/ drive. If you installed pip and Python to a different drive, use that one instead.
Alternatively, you could do this in your
~/.bashrc file for Git Bash. Enter,
vim ~/.bashrc to open the bashrc file. This is a file that executes every time you open a shell window. You’ll have to re-open your shell to get the changes that you make to the bashrc file.
A few other things to note:
- You MUST use single quotes as double quotes will not work.
- You MUST escape your \ slashes.
- You MUST use Windows style slashes (\). Unix style (/) will not work.
- You MUST escape your spaces in the path. If YOUR_USERNAME has a space you would enter the following:
alias pip='C:\\Users\\YOUR\ USERNAME\\AppData\\Local\\Programs\\Python\\Python36\\Scripts\\pip3.exe'
This can be handy if you don’t think you should edit the path. There’s more than one way to crack an egg. Creating an alias will just make pip automatically call that
pip3.exe you pointed it to. However, you may need to add the “Scripts” folder to the path in order to find some modules you installed.
On Windows especially, it seems to nearly always be safe to append to the path. But I always do that little trick to make sure I have an alias around just in case.