Are you looking for ways to fix "pip: command not found" error message?
Pip, short for Preferred Installer Program, is a package management program written in Python and for Python. It can manage local packages, install/update them from Python Package Index (PyPI) and remove them at will. Users can also use pip to fetch packages from other package repositories as well, provided that they're compatible with PEP 503.
Installing pip is easy, and should be easy, but still, there are common problems that happens to people from time to time, one of them is the annoying "pip: command not found" message, even though you've just installed pip.
This article is going to explain why "pip: command not found" sometimes pops up and provide a few possible fix to the error message.
Why "pip: command not found"
The error message simply indicates that the system cannot find pip's executable in places that it supposed to be.
The first thing you need to check is whether pip directory is included in
PATH environment variable. Most operating systems look for executables and binaries in a specific set of places. The list of all those places is stored in an environment variable, often named
Another thing that can cause the problem is that the installed version of pip's binary may not be named
pip, hence, invalidate the command.
If you haven't been able to identify the problem, the simplest way to fix is to reinstall
pip. Please note that most of the time, reinstalling
pip won't cause any problem because all its code is contained in a single binary file, and the
pip command simply call that binary. Having two identical executable binary in the same system won't ever be a problem at all.
Reinstall pip using package managers
Python is open-source and popular, therefore, it's no surprise that almost every major operating system include it in their standard distributions, or provide easy ways to install it.
In Debian/Ubuntu and its derivatives, you can run
sudo apt install python3-pip
In CentOS, RHEL and other distribution based on them, you have to add EPEL repository before actually install
yum install epel-release yum install python-pip
Arch Linux uses
pacman instead of
yum, so the command to install
pip should be
pacman -S python-pip
On a Fedora system, one can install
pip with the following command
dnf install python3-pip
Mac users have to run a
brew command to get
pip sorted out along with Python
brew install python
Most of the time, running one of the above command alone will fix the problem right away. You can verify it’s a successful installation with the command below.
Reinstall pip using get-pip.py
If installing pip using package managers doesn't work for you, try using
get-pip.py, the official way to install
pip, as per pip's official documentation page.
get-pip.py is a bootstrapping script that enables users to install
wheel in Python environments that don't already have them.
Let's suppose you're using Linux and already have
wget installed on your system, you can run the following command to install
pip. Please remember that in a few specific installation, you have to replace
python3 to execute the right Python version.
wget https://bootstrap.pypa.io/get-pip.py python get-pip.py
Reinstall pip using ensurepip
Recent versions of Python, specifically from Python 3.4, are bundled with a new
ensurepip module as part of the standard packages. The
ensurepip provides support for bootstrapping the
pip installer into an existing Python installation or virtual environment.
ensurepip bootstrapping approach reflects the fact that
pip is an independent project with its own release cycle, and the latest available stable version is bundled with maintenance and feature releases of the CPython reference interpreter.
You can simply run the following command to get
pip installed. Please remember that in a few specific installation, you have to replace
python3 to execute the right Python version.
python -m ensurepip
More information on ensurepip can be found at ensurepip — Bootstrapping the pip installer.
Double-check PATH environment variables
There are also a chance that
pip path is not included in PATH environment variables. Most of the time,
pip should be placed in
/usr/local/bin in Linux and
$HOME/homebrew/bin in MacOS.
You should add the following line to
~/.bash_profile to add
/usr/local/bin to PATH every time the system starts and see if the problem goes away.
On MacOS, replace
$HOME/homebrew/bin so it would look like this:
Once you're done the editing, restart the computer.
Add pip as an alias for pip3
A common scenario is that the installed
pip executable is named
pip3. Python 3 is not backwards-compatible, which means that programs that are written in Python 2 won't run in Python 3 and vice versa. In order to keep the standard legacy applications, in specific versions, OSes keeps both Python 2 and Python 3. In that case, pip for Python 2 will be executed with
pip and the one for Python3 is named
Run the following command to see if
pip3 is actually installed.
The system should response back a message indicates the
pip version along with the Python version.
[email protected]:~$ pip3 --version pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
Now you have two options. You can use
pip3 as it is or you can change the alias so that
pip actually call
pip3 executable. If you prefer the latter, run this command
You would have to add the line above to
~/.zprofile (in case you use ZSH) if you want the alias to persist through restarts.
We hope that the solutions above works for your case. If it didn't, there may be something seriously wrong with your install, your best bet would be to reinstall the whole operating system from scratch or use another
pip alternative such as conda.
You may like our other guides for Python to fix common error messages in Python, including "[Errno 32] Broken pipe" in Python, How to fix locale.Error: unsupported locale setting in Python or How to fix “unindent does not match any outer indentation level” indentation error in Python.