Python

audience developer
level all
topic Python
subtopic Installation

Command not found: pip

How to fix command not found pip on Mac. For zsh or bash. Python pip install command not found. You'll see the command not found pip error when Python is not installed or the Mac $PATH is not set correctly.

You'll encounter the error zsh: command not found: pip when trying to install a Python application or software library. This error occurs when the system's shell (zsh or bash) can't find the pip command. Pip is the standard package manager for Python, for installing and managing software packages written in Python. Python automatically includes pip; if Pip is not found, Python is not installed or the Mac $PATH is not set correctly.

Before you get started

You'll need a terminal application to fix the error. Apple includes the Mac terminal but I prefer Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and worth a try.

Is pip what you need?

Many tutorials and READMEs assume you're familiar with Python and the Pip installer. However, installing Python and using Pip is complicated, especially if you're new to Python. This guide will help you fix the command not found: pip error on macOS.

At the end of this article, I've written about "How to use Pip correctly." It's important to be aware that often you should not use pip install <package> and instead use a more appropriate alternative. First, though, let's consider the error zsh: command not found: pip and how to fix it.

The error zsh: command not found: pip

This is the error you'll see:

$ pip install <package>
zsh: command not found: pip

You'll see zsh: command not found: pip because you are trying to run the Pip package manager in the terminal. The error message shows that the Zsh shell ("the command line interpreter") cannot find the Python command.

If you see an error that begins with bash... you are using the Bash shell.

$ pip install ...
bash: command not found: pip

If you are using the Bash shell, you likely have an older version of the macOS. Check macOS and update macOS and switch to the Zsh shell.

Fix error zsh: command not found: pip

Things to try:

  1. Depending on your needs, you may need to install Pipx.
  2. You may need to restart your Terminal ("reset the shell").
  3. If a system Python is installed but not in the $PATH, you can alias pip.
  4. If a newer Python version is installed but not in the $PATH, you can set the $PATH.
  5. You may need to install Python.

Do you need Pipx?

Pipx is a tool to install and run stand-alone Python applications, utilities, or tools. There are a growing number of stand-alone programs that require Python to run, such as Youtube-dl, a command-line utility to download videos from YouTube. In addition to stand-alone Python programs, Python programming tools, such as Ruff, a Python code formatter, should be installed with Pipx.

If you are only installing a Python program, and you are not developing new software in Python, see our guide:

If you are programming in Python, and trying to install a software library, read on to fix the zsh: command not found: pip error.

Restart your Terminal

Just to be sure, quit the Terminal application and launch the Terminal again. Then try:

$ pip --version

It's an obvious solution but worth trying. A restart should display the Pip version number.

If you still see zsh: command not found: pip, read on.

Is the system Python installed?

Try pip3 --version and which -a pip3 to check if Python was installed with Xcode Command Line Tools.

$ pip3 --version
pip 21.2.4 from /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)
$ which -a pip3
/usr/bin/pip3

If you see /Library/Developer/CommandLineTools/Library/Frameworks/Python3..., you have the system Python (and Pip) installed by Xcode Command Line Tools. If you are programming in Python, don't use the system Python. Instead, install another version of Python (see Mac Python and set the Mac PATH.

If you just want to run Python scripts or command-line utilities, you can alias the pip command to pip3 to install packages (but it's better to Install Pipx). Add the following line to your .zshrc file. See the article alias python3 to python for more information:

alias pip='pip3'

For this change to take effect, you'll either need to restart your terminal or reload your .zshrc file by entering source ~/.zshrc.

Check if Python is installed

Check if Python is installed with python --version.

$ python --version
Python 3.12.3

Pip is installed automatically with Python, so it's unusual to run the command python successfully and then run pip and see zsh: command not found: pip. If you have Python installed, you should be able to run the pip command.

If you can run the command python but not pip, you can try a special command that installs Pip:

$ python -m ensurepip --upgrade

This command will install Pip if it is not already installed, but otherwise does nothing. If Pip is already installed, you'll see the message Requirement already satisfied: pip in ....

Setting the $PATH for Python

If you check for Python with python --version and you get the error zsh: command not found: python, either Python is not installed or the $PATH is not set correctly.

To troubleshoot, see my guide:

If you have Python installed, you need to set the $PATH for Python. The $PATH is an environment variable that tells the shell where to find the Python command.

How you set the $PATH variable will depend on how you installed Python. You may have installed Python with Homebrew, with Pyenv, the official Python installer, with Rye, or other methods. In the guide, you'll find instructions to set the $PATH for various ways you may have installed Python.

Adjusting the $PATH for Python will also allow you to run the pip command because Pip is installed with Python. Note that adjusting the $PATH for Python helps you set up your system for installing libraries and programming. If you are using Pipx to install and run Python programs, but not programming with Python, you don't need to set the $PATH for Python, but you will need to set the $PATH for Pipx.

If Python is not installed

If you've checked for Python and you are sure it was not previously installed, or if you only have the system Python that comes with Xcode Command Line Tools, and you want to start programming in Python, you can read the guide Mac Python about your options for installing Python. I suggest to install Python with Rye for an all-in-one tool to manage Python versions and virtual environments, and install packages. With Rye, you won't use pip install <package>; instead you'll use rye add <package> and rye sync. Rye is a great tool for both beginners and experienced Python programmers.

How to use Pip correctly

I've written elsewhere about how to use Pip correctly (see the the article Pip Install). In a nutshell:

  • If you are installing a stand-alone Python program, Install Pipx and use pipx install <package>.
  • If you are programming in Python, use Rye and install packages with rye add <package> instead of pip install <package>.

If you are programming in Python and still want to use Pip, not Rye, you should use a virtual environment with Venv and avoid using the "bare" pip install <package> command. Instead, use python -m pip install <package> to avoid path issues.

Using python -m pip ensures that the pip executable associated with the specific Python interpreter you are using is called. It means you are installing packages within the activated virtual environment rather than the global environment. This is a best practice to avoid conflicts between project dependencies. Directly calling pip relies on the Mac PATH to locate the pip executable. This can lead to situations where the pip command points to a different version of pip than expected. By using python -m pip, you avoid this ambiguity, ensuring the package is installed in the environment associated with the current Python interpreter.

What's next

My mac.install.guide is a trusted source of installation guides for professional developers. Take a look at the Mac Install Guide home page for tips and trends and see what to install next.