The pip: command not found error occurs when you try to use the pip package manager but your system does not find the pip executable.
This is simply because you haven't installed pip, or you installed but not added it to the system PATH.
So the solution to fix this error is to install pip, then add it to the system PATH.
You can follow the quick steps below to fix the pip: command not found error in Python.
Table of Contents
1. Installing Python
Before fixing the pip: command not found error, make sure Python is installed.
To check if Python is installed, run python --version
in the terminal. If you see the version of Python installed on your system, you can skip this section.
Python x.x.x
Otherwise, if you get the following error, you will need to install Python.
python: command not found # or 'Python' is not recognized...
To fix this error, you can see the following posts:
- Fixing the python: command not found Error on Linux and macOS.
- Fixing the 'python' is not recognized as an internal or external command on Windows.
2. Installing pip
After verifying that Python is installed, you need to install pip. To check if pip is installed, run the following command:
pip --version # or pip3 --version
If pip is installed, you will see the version of pip installed on your system. Then you can skip this section.
pip x.x.x from /path/to/pip (python x.x)
If pip is not installed, you will see the following error:
'pip' is not recognized as an internal or external command, operable program or batch file.
Installing pip on Windows
- Download the get-pip.py script.
- Open a Command Prompt and navigate to the directory where you downloaded the get-pip.py file.
- Run the following command:
python get-pip.py
(orpython3 get-pip.py
if it says "Python was not found", this is usually because you are using Python 3.x).
Installing pip on macOS and Linux
- Open a Terminal window.
- Install pip by one the following commands:
sudo apt install python3-pip
(recommended)python -m ensurepip
(orpython3 -m ensurepip
if it says "Python was not found")
Then run the following command again to check if it is installed correctly:
pip --version # or pip3 --version
In case you still get the error, continue to the next section.
3. Adding pip to the system PATH
Usually, pip is automatically added to the system PATH during installation. The system PATH is where the operating system looks for executables when you run a command in the terminal.
However, if you still get the pip: command not found error, you will need to add it manually.
Adding pip to the system PATH on Windows
- Open the Start menu and search for Environment Variables.
- Click Edit the system environment variables.
- Click the Environment Variables button.
- Under System Variables, scroll down and find the Path variable. Click Edit.
- Click New and enter the path to your Python installation's Scripts folder. This will typically be something like
C:\PythonXX\Scripts
, whereXX
is the version of Python you have installed. - Click OK to close all windows and save your changes.
Adding pip to the system PATH on MacOS
Usually, pip will automatically be added to PATH on MacOS and Linux, so the section below is optional.
- Open a terminal window.
- Open your shell configuration file. This will typically be
~/.shellrc
, or similar. - Add the following line to the file:
export PATH="$HOME/Library/Python/x.x/bin:$PATH"
, replacex.x
with your Python version - Save and close the file.
- Run
source ~/.shellrc
(depending on which file you edited) to apply the changes.
Once you've added pip to the system PATH, you can run pip commands in the terminal without encountering the "pip: command not found" error.
Adding pip to the system PATH on Linux
- Open a terminal window.
- Open your shell configuration file. This will typically be
~/.shellrc
, or similar. - Add the following line to the file:
export PATH="$HOME/.local/bin:$PATH"
- Save and close the file.
- Run
source ~/.shellrc
(depending on which file you edited) to apply the changes.
4. Verifying the pip Installation
After installing pip and adding it to the system PATH, you should verify that the installation was successful.
To do this, open a terminal or command prompt and run the following command:
pip --version
or
pip3 --version
This will display the version of pip installed on your system, as well as the location of the pip executable. If you see output similar to the following, your installation was successful:
pip x.x.x from /path/to/pip (python x.x)
That's all, you can now use pip to install Python packages.
Conclusion
In this tutorial, we have learned how to fix the pip: command not found error in Python by installing and adding it to the system PATH.
If you have any questions, leave a comment below. Good luck!