In this article, we will see how to solve zsh: command not found: pip error if you are also getting this in your Linux/macOS system. Few days when I was trying to install a python package in my System using pip utility then I suddenly noticed zsh: command not found: pip error on the output. Although this is a very common error faced by many python beginners and professionals due to multiple different reasons but in my case it was due to I have the latest pip version installed in my system i.e pip3 but I was trying to use the older pip command.
So I thought there are lot of folks out there wondering why zsh: command not found: pip error pops up even if they have pip utility installed in their system or in most of the cases it might not be installed at all. For all those cases it is worth to write an article explaining the steps to follow on different Linux distribution and macOS systems to fix this error. So without further delay, let's begin !!
Solved "zsh: command not found: pip" in Linux/macOS
pip is a very famous and most commonly used python package manager to install, manage and delete python packages from the System. Almost all the python developers and programmers uses this utility to easily manage their python packages. Sometimes it so happen that whenever we try to use pip to perform certain package management operation then we end up in getting zsh: command not found: pip error as shown below.
ubuntu% pip --version zsh: command not found: pip
While the above error could come due to any reasons but most of the time it is due to either python or pip utility not installed in the Linux/macOS System or if it is installed then you have the latest pip version i.e pip3 instead of pip. So depending on the system you are using, you can try below different methods to deal with the error.
Method 1: Using brew utility
If you are using a Linux system which has brew package manager or you are using a macOS based system then you can try this method to fix the error. You just need to install the python package by using
brew install python command as shown below. This will install the latest available python version i.e python3 and with it the latest available pip utility i.e pip3.
ubuntu% brew install python ==> Downloading https://ghcr.io/v2/homebrew/core/python/3.10/manifests/3.10.8-1 Already downloaded: /home/cyberithub/.cache/Homebrewfirstname.lastname@example.org_manifest.json ==> Downloading https://ghcr.io/v2/homebrew/core/python/3.10/blobs/sha256:2e0127173d003685094f79bf5f94652f66af803643cc89ae5dca0a5af8342e47 Already downloaded: /home/cyberithub/.cache/Homebrewemail@example.com_64_linux.bottle.1.tar.gz ==> Pouring firstname.lastname@example.org_64_linux.bottle.1.tar.gz ==> /home/linuxbrew/.linuxbrew/Cellaremail@example.com/3.10.8/bin/python3.10 -m ensurepip ==> /home/linuxbrew/.linuxbrew/Cellarfirstname.lastname@example.org/3.10.8/bin/python3.10 -m pip install -v --no-deps --no-index --upgrade --isolated --target=/home/linuxbrew/ ==> Caveats Python has been installed as /home/linuxbrew/.linuxbrew/bin/python3 Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to `python3`, `python3-config`, `pip3` etc., respectively, have been installed into /email@example.com/libexec/bin You can install Python packages with pip3 install <package> They will install into the site-package directory /home/linuxbrew/.linuxbrew/lib/python3.10/site-packages tkinter is no longer included with this formula, but it is available separately: brew install firstname.lastname@example.org See: https://docs.brew.sh/Homebrew-and-Python ==> Summary 🍺 /home/linuxbrew/.linuxbrew/Cellaremail@example.com/3.10.8: 2,667 files, 59.2MB ==> Running `brew cleanup firstname.lastname@example.org`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Method 2: Using apt or apt-get
If you are having any Ubuntu/Debian/Linux Mint based systems, then you can try this method where you just need to run
sudo apt install python3-pip command to install
pip3 utility if you are using latest python version i.e python3. In case, you are using older version i.e python2 then you need to run
sudo apt install python-pip command.
ubuntu% sudo apt install python3-pip Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libfwupdplugin1 libllvm11 libxmlb1 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libexpat1-dev libpython3-dev libpython3.8-dev python-pip-whl python3-dev python3-distutils python3-setuptools python3-wheel python3.8-dev zlib1g-dev Suggested packages: python-setuptools-doc The following NEW packages will be installed: libexpat1-dev libpython3-dev libpython3.8-dev python-pip-whl python3-dev python3-distutils python3-pip python3-setuptools python3-wheel python3.8-dev zlib1g-dev 0 upgraded, 11 newly installed, 0 to remove and 28 not upgraded. Need to get 7,274 kB of archives. After this operation, 28.4 MB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 libexpat1-dev amd64 2.2.9-1ubuntu0.6 [116 kB] Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 libpython3.8-dev amd64 3.8.10-0ubuntu1~20.04.6 [3,949 kB] Get:3 http://in.archive.ubuntu.com/ubuntu focal/main amd64 libpython3-dev amd64 3.8.2-0ubuntu2 [7,236 B] Get:4 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 python-pip-whl all 20.0.2-5ubuntu1.6 [1,805 kB] Get:5 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 zlib1g-dev amd64 1:1.2.11.dfsg-2ubuntu1.5 [155 kB] Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 python3.8-dev amd64 3.8.10-0ubuntu1~20.04.6 [514 kB] Get:7 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 python3-distutils all 3.8.10-0ubuntu1~20.04 [141 kB] Get:8 http://in.archive.ubuntu.com/ubuntu focal/main amd64 python3-dev amd64 3.8.2-0ubuntu2 [1,212 B] Get:9 http://in.archive.ubuntu.com/ubuntu focal/main amd64 python3-setuptools all 45.2.0-1 [330 kB] Get:10 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 python3-wheel all 0.34.2-1 [23.8 kB] Get:11 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 python3-pip all 20.0.2-5ubuntu1.6 [231 kB] Fetched 7,274 kB in 3s (2,198 kB/s) Selecting previously unselected package libexpat1-dev:amd64. (Reading database ... 203905 files and directories currently installed.) Preparing to unpack .../00-libexpat1-dev_2.2.9-1ubuntu0.6_amd64.deb ... Unpacking libexpat1-dev:amd64 (2.2.9-1ubuntu0.6) ... Selecting previously unselected package libpython3.8-dev:amd64.
Method 3: Using Python Script
You also have the option to install pip utility through Python Script. But for that you should have wget utility available in your System. Then you just need to run
wget https://bootstrap.pypa.io/get-pip.py command to download the python script in your local system.
ubuntu% wget https://bootstrap.pypa.io/get-pip.py --2022-12-10 18:59:36-- https://bootstrap.pypa.io/get-pip.py Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 220.127.116.11, 2a04:4e42:5a::175 Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|18.104.22.168|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2569500 (2.5M) [text/x-python] Saving to: ‘get-pip.py’ get-pip.py 100%[============================================================================>] 2.45M 7.50MB/s in 0.3s 2022-12-10 18:59:36 (7.50 MB/s) - ‘get-pip.py’ saved [2569500/2569500]
Now to install the utility, you need to run the python script by using
python3 get-pip.py as shown below. In case, you are using older python version i.e python2 then you need to use
python get-pip.py command.
ubuntu% python3 get-pip.py Defaulting to user installation because normal site-packages is not writeable Collecting pip Downloading pip-22.3.1-py3-none-any.whl (2.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 4.7 MB/s eta 0:00:00 Installing collected packages: pip WARNING: The scripts pip, pip3 and pip3.8 are installed in '/home/cyberithub/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed pip-22.3.1
Method 4: Using dnf utility
If you are using any RHEL/CentOS based latest systems with latest python version installed, then you can install pip utility by simply using
sudo dnf install python3-pip command as shown below. In case, you are using older python version i.e python2 then you need to run
sudo dnf install python-pip command.
[cyberithub@centos8]~% sudo dnf install python3-pip Last metadata expiration check: 0:00:15 ago on Sat 10 Dec 2022 09:01:52 AM EST. Dependencies resolved. ============================================================================================================================================================= Package Architecture Version Repository Size ============================================================================================================================================================= Installing: python3-pip noarch 9.0.3-20.el8 appstream 20 k Installing dependencies: python36 x86_64 3.6.8-38.module_el8.5.0+895+a459eca8 appstream 19 k Transaction Summary ============================================================================================================================================================= Install 2 Packages Total download size: 39 k Installed size: 16 k Is this ok [y/N]: y Downloading Packages: (1/2): python3-pip-9.0.3-20.el8.noarch.rpm 107 kB/s | 20 kB 00:00 (2/2): python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64.rpm 102 kB/s | 19 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 198 kB/s | 39 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64 1/2 Running scriptlet: python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64 1/2 Installing : python3-pip-9.0.3-20.el8.noarch 2/2 Running scriptlet: python3-pip-9.0.3-20.el8.noarch 2/2 Verifying : python3-pip-9.0.3-20.el8.noarch 1/2 Verifying : python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64 2/2 Installed: python3-pip-9.0.3-20.el8.noarch python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64 Complete!
After following above methods, if you now check again by using
pip3 --version command, then you will notice that pip utility is available.
ubuntu% pip3 --version pip 22.2.2 from /email@example.com/lib/python3.10/site-packages/pip (python 3.10)
In case, you are not comfortable in using pip3 command then you can create an alias of pip3 and use pip command. For that you need to first identify the path of pip3 binary utility by using
which pip3 command as shown below.
ubuntu% which pip3 /home/cyberithub/.local/bin/pip3
Then add the above path as an alias to pip utility under
.zshrc file as shown below.
ubuntu% nano ~/.zshrc alias pip='/home/cyberithub/.local/bin/pip3'
Ctrl+X to save and exit. Now try to run
pip --version command. You will notice that it will start working as expected.
ubuntu% pip --version pip 22.3.1 from /home/cyberithub/.local/lib/python3.8/site-packages/pip (python 3.8)
Even after following above methods, if you are still getting
zsh: command not found: pip error then it is probably because you have installed the utility on some location which is not visible to the System. So to make it visible, you need to add the installation path to the global
$PATH environmental variable as shown below.
ubuntu% export PATH=$PATH:/u01/.local/bin/pip3
However, the above step is just a temporary one. To make the changes permanent, you need to put an entry in
Hopefully, above solutions would be enough to solve
zsh: command not found: pip error. Please let me know your feedback in the comment box !!