When using Python, you might need to install and use certain packages. And there is a command available for that known as 'pip'.
With pip, you can install, upgrade, and uninstall various Python packages. You'll learn how to use it, and how to handle pip errors, in this article.
How to use pip
Pip is a command that you can use on the Linux or Mac command line. You can select a package from here.
Below is an example of how you would install the
mock-open package with
pip3 install mock-open
As this package was already installed, we are getting the message that the requirement is already met.
Note that I have used pip3 because I am using Python3. We'll discuss this in detail later.
What is the error
pip: command not found?
Sometimes when you are installing packages, you might face the error:
pip: command not found. This error could be due to the following reasons:
- Pip is not installed.
- Pip is installed, but it is not compatible with the current environment.
On Linux, you must install the pip package manager separately as it is an independent package. But on Mac, you do not need to install pip manually, as long as you are working with Python 3.x.
Troubleshooting the error
pip: command not found
- Check if pip is installed.
On Mac and Linux, you can use the below command to check if pip is installed.
python3 -m pip --version
If pip is not installed, you can follow the install steps here for your respective OS.
2. Upgrade pip to the latest version
If pip is still not working, try to upgrade pip to the latest version:
python -m pip install --upgrade pip
3. Fix environment issues
It is possible that you are trying to use the wrong version of pip. For example,
pip3 works for
pip works only for
You can check your Python version on Linux and Mac like this:
If your code is in Python 2 and you still wish to use an older version of pip, you can follow the below steps.
Note that Python 2 has reached end of life. It is better to upgrade your code base to Python 3 and use the latest version of pip.
Follow the below steps only if you are using Python2:
- Install pip (older version)
sudo easy_install pip
This command installs the pip command onto your system.
Now try to use the pip command – it should work without errors.
Pip is a useful command to install Python packages. We have covered some troubleshooting methods for the error
pip: command not found.
I hope you found this tutorial helpful.
Let's connect on Twitter!
You can read my other posts here.