[Solved] “pip command not found”

PIP is an essential tool for managing Python packages on Linux systems. It allows users to easily install, upgrade, and manage Python packages and their dependencies, simplifying the process of developing Python applications. With Pip, Linux users can quickly install any package from the vast Python Package Index (PyPI) repository, making it easy to access and use the latest Python libraries and tools.

Sometimes, while trying to use the pip command, an error “pip: command not found” occurs on the Linux systems. This post will provide the possible causes of the error “pip command not found” and the solutions to rectify this.

How to Fix the “pip: command not found” Error?

The “pip: command not found” error occurs if the package is not installed, the environment is not set or is incorrectly set, the pip is not upgraded, etc. Let’s have a look at these reasons in a bit of detail:

PIP not Installed

If the package executable is missing from the system, the system won’t be able to run it, thus resulting in an error, “pip: command not found.”

The Environment for PIP is not Set

Let’s say you have installed the PIP but are redirecting to a location other than the default. Thus, the pip command cannot locate the executables.

PIP is not the Latest One

If you use an old pip that does not support the package/module you are trying to install, you also get the same error.

Let’s demonstrate this: we are trying to install the “django-heroku” module using the PIP. Our system is not yet equipped with the PIP. Thus, the error arises in installing PIP to proceed with this command.

pip command not found error | linuxgenie.net

The above-stated reasons are the possible scenarios that invoke the error “pip: command not found” error on Linux. Now, let’s have a look at the solutions to get rid of this.

Solution 1: Install PIP

The installation commands for the PIP tool vary from distribution to distribution, i.e., depending on the package manager. Let’s list the commands for the most used Linux distributions:

$ sudo apt install python3-pip        #Debian-Based
$ sudo pacman -S python3-pip          #Arch-Based
$ sudo yum install python3-pip        #CentOS/RHEL-Based
$ sudo dnf install python3-pip        #Fedora-Based

installing pip | linuxgenie.net

Note: If you use the PIP for Python 2, use the package name “python-pip” instead of “python3-pip”.

Solution 2: Update Path Environment Variable

The latest releases of the distributions set the environment variables with the installation. However, it may not be true in all cases, as the installation directory may differ as per the user’s requirement. So, you need to export the PATH environment variable to the directory of executables so that your system can recognize the command. To do so, a two-step procedure needs to be adapted:

Step 1: Locate the PIP Executable

First, you need to find the location of the PIP executable using the command:

$ which pip

pip command path | linuxgenie.net

Step 2: Update the Path Environment

It can be seen that the primary directory is “/usr/bin,” which may differ in your case. Now, open the “.bashrc” file using any text editor:

$ sudo nano .bashrc

Add the following line at the end of the file. Remember to replace the actual path of the PIP executable that you found in Step 1:

export PATH="usr/bin:$PATH"

adding pip's path in nano

After that, either restart the terminal or use the following command to refresh the shell environment:

$ source .bashrc

refreshing bash shell | linuxgenie.net

Doing so will update the path of the executable, and your system will recognize the PIP command.

Solution 3: Upgrade PIP

The older versions of PIP might not be compatible with the module/package you want to install. So, it’s time to upgrade the PIP using the below command:

$ python3 -m pip install --upgrade pip

upgrading pip | linuxgenie.net

Solution 4: Create a Symbolic Link

Sometimes, the user intends to install the package at some other location than the default, or the user moves the executable from the default directory. The default executable directory cannot be reached easily in such a case.

Thus, creating a symbolic link of the current installation directory is recommended to the default directory where the default executables are present, and your system searches that directory. The ln command is used in the following manner to serve the purpose:

Use the “ln” command with the “s” flag to create a symbolic link.
Then, write the exact path of the directory where the installation is performed.
Lastly, write the name of the directory where the package is installed.

$ sudo ln -s <Path/to/Custom/Installation> /usr/local/bin/pip

Replace the “Path/to/Custom/Installation” with the actual path where you have installed PIP.

Wrap Up

The “pip: command not found” usually occurs when using the pip tool, but the pip tool is not installed or installed at some other directory where your system cannot detect the executable. To fix this, the users must install the respective PIP version on their Linux distribution. To fix the path issues, either export the PATH environment variable or create a symbolic link to the directory where pip is installed.

Apart from that, upgrading the PIP might also get you out of this problem. Following the solutions mentioned, you have learned to solve the “pip: command not found” error on Linux.

Visit Linux Genie for more troubleshooting posts.

Print Friendly, PDF & Email