Install Pip
How to use Pip on Mac to install Python packages for programs, scripts, and utilities.
Pip is the standard package manager for Python. When you enter the command python
in the Terminal (on the command line), you are executing the Python interpreter to run a Python program. The "Python standard library" is always available, but you can install additional packages to extend Python's capabilities. Pip is the built-in program that installs Python packages.
Before you get started
You'll need a terminal application to use Pip or Python. Apple includes the Mac terminal but I prefer Warp Terminal. Warp increases developer productivity, helping you remember easily-forgotten commands and adds AI troubleshooting. Download Warp Terminal now; it's FREE and worth a try.
How to use Pip correctly
Before you try to install a Python package with Pip, consider that Pip is often not the right tool to use! Python is used for two things: running programs and writing code for software projects. If you want to run a standalone program that requires Python, see the guide:
If you are developing software, you can use Pip to install software libraries. To use Pip successfully, you will have to use Python's virtual environment tools to avoid dependency conflicts. The combination of Pyenv, Venv, and Pip is a standard way to manage Python projects, but can be cumbersome. I recommend Rye as an alternative. Rye is an all-in-one tool that combines the functionality of Pyenv, Venv, and Pip. Rye simplifies the process of managing Python projects, making it easier to create and activate virtual environments and install packages. If you'd like to streamline your Python workflow with a single tool, see the guide:
For more on the correct use of Pip, see my guide:
Here I'll explain how to use Pip with Pyenv and Venv, a standard Python development environment.
Common errors
When you try to run pip install <package>
in the Terminal, you may encounter the following errors:
The links above will take you to the troubleshooting guides for these errors.
How to install Pip
Since Python 3.3, Python installations come with pip
by default. You don't need to install Pip.
You can check that Pip is available by running the command pip --version
in the Terminal. If you see the error zsh: command not found: pip
, see the troubleshooting guide zsh: command not found: pip.
If Pip is not available, it's likely that you need to install Python since Pip comes with Python. If you haven't installed Python,and you're beginning a programming project, you should install Python using Pyenv (unless you prefer Rye).
Install Pyenv to use Pip
Start by installing Pyenv using Homebrew.
After you've installed Pyenv and a current Python version, you can use Pip to install Python packages.
Pip is included with Python
Since Python 3.3, Python installations come with pip
by default.
Check that Pip is available:
$ pip --version
pip 24.0 from /Users/username/.pyenv/versions/3.12.2/lib/python3.12/site-packages/pip (python 3.12)
If you've installed Pyenv, the which
command will show that Pyenv shims are intercepting calls to pip
.
$ which pip
/Users/username/.pyenv/shims/pip
Install a Python package
You can install any Python package from the Python Package Index. Here we'll install the cowsay utility.
$ pip install cowsay
Collecting cowsay
Using cached cowsay-6.1-py3-none-any.whl.metadata (5.6 kB)
Using cached cowsay-6.1-py3-none-any.whl (25 kB)
Installing collected packages: cowsay
Successfully installed cowsay-6.1
Recent versions of Pip implement PEP 668 to prevent attempts to install a package into a system Python. Using Pyenv with pip
, you'll avoid an error: externally-managed-environment
that results from violating PEP 668 (see error: externally-managed-environment). However, Pyenv and pip
don't prevent clashes between packages required by different projects. You'll begin to encounter dependency conflicts if you have multiple projects that require different versions of the same packages.
With Pyenv, any package installed with Pip will be installed in a common folder for a specific Python version and shared with any other projects that use the same Python version. That's because Pyenv manages Python versions, not projects. You should install pyenv-virtualenv to isolate packages in different projects. Or use Rye for an all-in-one tool that takes a project-oriented approach.
Run Python
After installing a package with Pip, you can use the Python interpreter interactively (the REPL or Read-Eval-Print Loop).
$ python
Python 3.12.2 (main, Mar 24 2024, 13:24:12) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cowsay
>>> cowsay.cow('Hello World')
___________
| Hello World |
===========
\
\
^__^
(oo)\_______
(__)\ )\/\
||----w |
|| ||
>>>
Enter quit()
or type Control + D
to exit the 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.