Installing pip (Python's package installer) on macOS or OS X can be done in several ways. Below, I will detail the common methods.
Using the System's Built-in Python to Install pip
macOS versions prior to Catalina typically included Python 2 pre-installed, but starting with macOS Catalina, Python is no longer pre-installed on the system. If your system already has Python, you can install pip using the following command:
- Open Terminal (available in the 'Others' folder of Launchpad).
- Enter the following command to install pip:
bashsudo easy_install pip
This method uses easy_install, a module from the setuptools package, which can also be used to install Python packages.
Installing pip Using the Official get-pip.py Script
If your system does not have Python pre-installed, or if you need to install pip for Python 3, follow these steps:
- First, ensure Python is installed on your system. You can check this by entering
python3 --versionin the Terminal. - Download the
get-pip.pyinstallation script from the pip official website. - Run the following command in the Terminal:
bashpython3 get-pip.py
This will install pip and typically also install wheel, a tool for building Python packages.
Installing Python and pip via Homebrew
Homebrew is a package manager for macOS that can be used to install and manage software packages. If you haven't installed Homebrew yet, run the following command in the Terminal to install it:
bash/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
After installing Homebrew, you can install Python using Homebrew, which will also install pip. Run the following command in the Terminal:
bashbrew install python
This command will install the latest version of Python and pip.
Verifying the Installation
Regardless of the method used to install pip, you can verify the installation with the following command:
bashpip --version
Or for Python 3:
bashpip3 --version
The above are the common methods for installing pip on macOS or OS X.