pip allows you to download packages you can reference in your Python code. If you try to install a package using pip without having the package manager installed on your computer, you’ll encounter the
pip: command not found error.
In this guide, we discuss the cause of this error. We then walk through two potential solutions to this error so you can fix the problem you are encountering.
Find Your Bootcamp Match
- Career Karma matches you with top tech bootcamps
- Access exclusive scholarships and prep courses
pip: command not found
On Linux, the pip package manager is an independent package. This means you must install pip separately from Python. On Mac, you do not need to worry about installing pip manually, as long as you are working with Python 3.x.
command not found error is raised on Linux if there is no command on the system by the name you have referenced. You must have pip installed on your system before you can install packages.
Python 2 has reached its end of life. This means Python 2 is no longer being actively maintained or changed. You should try to move your code over to a codebase that supports Python 3. When you are working with Python 3, use pip3 instead of pip.
Cause #1: Using the Wrong Environment
Python 2.7 and other versions of Python 2 rely on the bash pip command whereas the Python 3 command relies on pip3. We have written a program called hello.py which uses a print() statement to display “Hello world!” to the command line console:
This program was written in Python 3. To execute this program, we will use the python3 command:
Our code prints out the message “Hello world!” to the console.
Let’s say that we want to install the “requests” library so we can make a web request in our script. Because we are using Python 3, we should use pip3. If we try to use pip, we’ll encounter an error:
pip: command not found
We do not have pip installed because we are working in a Python 3 development environment. If we replace
pip3, our command will work:
pip3 install requests
Our command shows us the installation process:
Requirement already satisfied: requests in ./Library/Python/3.8/lib/python/site-packages (2.24.0) …
We already had the requests library installed. If we did not have the requests library installed, we would see pip3 install the library.
The pip3 command uses the pip3 Python package manager to install the “requests” library. We have configured pip3 which means this command works.
If you do not already have pip3 installed, you can install it using apt-get:
sudo apt-get -y install python3-pip
After you have run this command, you’ll be able to use the pip3 package manager on your system.
pip3 is bundled with Python 3 on MacOS so you do not need to run any additional commands. If you do not have pip3 installed already, you should try to reinstall Python 3. This will install pip3 automatically. You can install Python 3 using the brew command:
brew install python3
We now have both Python 3 and pip3 installed on our system.
Cause #2: Not Downloading Python 2 pip
pip: command not found error may occur if you have not installed Python 2 pip on your system. The below steps should be followed only if your code is written in Python 2. Otherwise, you should move your codebase over to Python 3 because Python 2 has reached its end of life.
To install pip in Python 2, you must use the
sudo easy_install pip
This command installs the pip command onto your system. If you do not already have
easy_install installed, install it using the following Linux command:
sudo apt-get install python-setuptools
easy_install tool is deprecated. This is because Python is moving its focus to Python 3 where pip3 is the main package manager that you should use for installing a package.
pip: command not found error is raised if you do not have pip installed on your system, or if you’ve accidentally used the pip command instead of pip3.
To solve this error, make sure you have installed both Python 3 and pip3 onto your system. If you are working with a legacy codebase, use
easy_install to install pip.
Now you have the skills you need to solve this error like a pro!
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.