Home//

pip: command not found: Easiest Way to Fix

pip: command not found: Easiest Way to Fix

Minh Vu

By Minh Vu

Updated Nov 16, 2023

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.

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.

shell
Python x.x.x

Otherwise, if you get the following error, you will need to install Python.

shell
python: command not found # or 'Python' is not recognized...

To fix this error, you can see the following posts:

2. Installing pip

After verifying that Python is installed, you need to install pip. To check if pip is installed, run the following command:

shell
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.

shell
pip x.x.x from /path/to/pip (python x.x)

If pip is not installed, you will see the following error:

shell
'pip' is not recognized as an internal or external command, operable program or batch file.

Installing pip on Windows

  1. Download the get-pip.py script.
  2. Open a Command Prompt and navigate to the directory where you downloaded the get-pip.py file.
  3. Run the following command: python get-pip.py (or python3 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

  1. Open a Terminal window.
  2. Install pip by one the following commands:
    • sudo apt install python3-pip (recommended)
    • python -m ensurepip (or python3 -m ensurepip if it says "Python was not found")

Then run the following command again to check if it is installed correctly:

shell
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

  1. Open the Start menu and search for Environment Variables.
  2. Click Edit the system environment variables.
  3. Click the Environment Variables button.
  4. Under System Variables, scroll down and find the Path variable. Click Edit.
  5. Click New and enter the path to your Python installation's Scripts folder. This will typically be something like C:\PythonXX\Scripts, where XX is the version of Python you have installed.
  6. 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.

  1. Open a terminal window.
  2. Open your shell configuration file. This will typically be ~/.shellrc, or similar.
  3. Add the following line to the file: export PATH="$HOME/Library/Python/x.x/bin:$PATH", replace x.x with your Python version
  4. Save and close the file.
  5. 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

  1. Open a terminal window.
  2. Open your shell configuration file. This will typically be ~/.shellrc, or similar.
  3. Add the following line to the file: export PATH="$HOME/.local/bin:$PATH"
  4. Save and close the file.
  5. 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:

shell
pip --version

or

shell
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:

shell
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!

You can search for other posts at home page.
Minh Vu

Minh Vu

Software Engineer

Hi guys, I'm the author of WiseCode Blog. I mainly work with the Elastic Stack and build AI & Python projects. I also love writing technical articles, hope you guys have good experience reading my blog!