Python: Fix command not found pip or pip3 on zsh shell


zsh command not found pip
zsh command not found pip

If you trying to install a package for Python using pip package manager on your macOS/Linux terminal using the zsh shell and you get error zsh: command not found: pip, one reason could be that you have pip3 installed with Python 3, so try pip3 install package-name, if this too gives the same error you need to first install pip3

Installing pip package manager for Python on macOS

  1. Open Terminal with zsh shell
  2. Now download the python file: get-pip.py
    % curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 1863k  100 1863k    0     0  2111k      0 --:--:-- --:--:-- --:--:-- 2129k
    
  3. Now lets run the script:
    python get-pip.py 
    
    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. 
    Please upgrade your Python as Python 2.7 is no longer maintained. 
    pip 21.0 will drop support for Python 2.7 in January 2021. More details about 
    Python 2 support in pip can be found at
     https://pip.pypa.io/en/latest/development/release-process/ 
    #python-2-support pip 21.0 will remove support for this functionality.
    Defaulting to user installation because normal site-packages is not writeable
    Collecting pip<21.0
      Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
         |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1.5 MB 827 kB/s 
    Installing collected packages: pip
      WARNING: The scripts pip, pip2 and pip2.7 are installed in 
    '/Users/code2care/Library/Python/2.7/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-20.3.4

Now lets test if we are able to install packages:

% pip3 install requests
Defaulting to user installation because normal site-packages is not writeable
Collecting requests
  Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 63 kB 4.4 MB/s 
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.8-py2.py3-none-any.whl (138 kB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 138 kB 7.7 MB/s 
Collecting charset-normalizer~=2.0.0; python_version >= "3"
  Downloading charset_normalizer-2.0.11-py3-none-any.whl (39 kB)
Collecting idna<4,>=2.5; python_version >= "3"
  Downloading idna-3.3-py3-none-any.whl (61 kB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 61 kB 3.5 MB/s 
Collecting certifi>=2017.4.17
  Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 149 kB 8.2 MB/s 
Installing collected packages: urllib3, charset-normalizer, idna, certifi, requests
 
Successfully installed certifi-2021.10.8 charset-normalizer-2.0.11 idna-3.3 requests-2.27.1 urllib3-1.26.8