Introduction
Pip is a package management system for installing and managing Python software and libraries. The packages managed by pip are stored in the Python Package Index (PyPI) repository.
In this tutorial, you will learn to install pip on macOS using three methods.
Prerequisites
- A system running macOS.
- Python installed.
- A user account with administrator-level privileges.
How to Install pip on Mac
The recommended way to install pip on Mac is using Python's ensurepip module. This section describes the pip installation via ensurepip and provides two alternative methods:
- Installing via Homebrew
- Using get-pip.py installation script.
Method 1: Install pip via ensurepip
Since version 3.4, Python can install pip without utilizing external commands or an internet connection. This feature is available through ensurepip, a module that supports bootstrapping pip to an existing Python installation.
Follow the steps below to install pip with ensurepip:
1. Open a new Terminal window.
2. Run the following command to start the installation:
python3 -m ensurepip
The output confirms the installation was successful.
![Install pip via ensurepip on macOS.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/output-from-python3-ensure-pip-install-pip-mac-update.png)
Method 2: Install pip on macOS via Homebrew
Another method to install pip on macOS is through Homebrew, an open-source package manager.
Note: If you do not have Homebrew installed on your system, read How to Install Homebrew on Mac.
On Homebrew, pip comes prepackaged with the Python installation. To install pip, install the Python formula with the following command:
brew install python
Homebrew installs the latest Python, pip, and setuptools
packages.
Note: If pip is not in your path after installing via Homebrew, the solution is to re-link. Run brew unlink python && brew link python
.
Since macOS already comes with a preinstalled version of Python, the brew command installs a separate copy. Having a separate installation:
- Allows you to use newer Python versions than those preinstalled on macOS.
- Adds a layer of protection to your system, as it provides isolation from the system dependencies.
Method 3: Install pip via get-pip.py
Another way to install pip on macOS is using the get-pip.py script. The script automatically downloads and installs the current pip package for Python.
Important: Install pip via get-pip.py
only with Python3 or later. This method doesn't work for earlier versions. Learn how to upgrade to Python3.
Follow the steps below to install pip with get-pip.py:
1. Check the Python version to make sure Python3 is installed:
python3 --version
2. Download pip by running the following command:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
The curl command allows you to specify a direct download link. Use the -o
option to set the name of the downloaded file.
3. Install the downloaded package:
python3 get-pip.py
Wait for the installation to finish.
How to Verify pip Installation
To verify that you have installed pip correctly, check the pip version on your system:
pip --version
The output shows which pip version you have on your computer.
How to Update pip on Mac
Update pip to a newer version by executing one of the following commands:
- The ensurepip command with the --upgrade option:
python3 -m ensurepip --upgrade
- The pip install command with the --upgrade option:
pip install --upgrade pip
Note: To upgrade pip with Homebrew, upgrade your Python version by running brew upgrade python
.
Update to a specific pip version by providing the version number to the pip install command:
pip install --upgrade pip==[version]
For example, to update to pip 21.2.4, type:
pip install --upgrade pip==21.2.4
How to Uninstall pip on Mac
Uninstall pip from your system with the following pip command:
pip uninstall pip
When prompted, start the removal by typing Y and pressing Enter. The output confirms the successful uninstallation of pip.
Conclusion
After reading this article, you should know how to install, update, and remove pip from your macOS system. Pip is a great way to manage and install packages, with over 50,000 packages available in its repository.
If you want to install pip on a different system, refer to one of our other tutorials Install pip on Windows, Install pip on CentOS 7, Install pip on CentOS 8, Install pip on Debian 9 or Install pip on Ubuntu.