Pip allows you to download, install, update and uninstall packages used in your projects. It is a simple and powerful command-line utility for Python developers.
In Linux, pip is packed as a separate tool and must be installed independently of the Python interpreter.
Hence, if you run the pip command on a system where pip is not installed, you will get the command not found
error.
Pip command Not Found
The command not found error occurs in Linux systems when the system cannot find the command with the specified name.
Therefore, the pip command not found error means that the system cannot find any binary with the name pip.
Let us discuss the potential causes of this error and how we can resolve it.
Cause 1 – PIP Not Installed
One of the causes of the pip command not found
error is that pip is not installed on the target system.
Since pip is installed as a separate package on most Linux systems, installing the Python interpreter will not have pip.
You can resolve this by installing pip as a separate package with your system's package manager.
Debian
sudo apt-get update
sudo apt-get install python3-pip -y
REHL/Fedora
sudo yum install python34-pip
Arch/Manjaro
sudo pacman -Syu python-pip
The commands above should install pip3 on all the systems. Keep in mind that the pip3 command is not the same as pip.
Cause #2 – Incorrect Pip
Although you may have pip installed, you can still get the command not found error when calling the pip command.
This is because the command to invoke pip will depend on the version of pip installed. For example, for Python3 pip, you will need to use the command:
pip3
For Python 2 pip, use the command:
pip
If you are absolutely sure that you need the Python2 pip, you can install it using the commands:
Debian
sudo apt-get install python-pip
REHL/Fedora
sudo yum install python2.7-python-pip
Manjaro/Arch
sudo pacman -Syu python2-pip
You can then verify that the pip command is working.
Alternative Fix
You may have Python 3 and its corresponding pip installed in some cases. However, you want to use pip instead of pip3 to invoke it.
That's where your shell aliases come to the rescue.
From our error zsh command not found pip
error, we know that we are working in the ZSH shell.
Hence, to link the alias pip to pip3, we can edit the .zshrc file:
nano ~/.zshrc
In the file, add the following entry:
alias pip='pip3'
The line above links the alias pip to the command pip3. We can then apply the changes by running the source command:
source ~/.zshrc
You can now verify that the pip command is working as:
pip –version
Output:
pip 21.2.4 from /home/debian/anaconda3/lib/python3.9/site-packages/pip (python 3.9)
The command should return the installed pip version.
Conclusion
The error zsh command not found
occurs when you run the pip command in the ZSH shell where pip is not installed.
Thanks to this tutorial, we know how to resolve this error by installing the correct pip version and linking pip3 to an alias.
Thanks for reading!!