How do I install pip on macOS or OS X?
Categories:
Mastering Python on macOS: A Comprehensive Guide to Pip Installation

Learn how to install pip, Python's package installer, on your macOS or OS X system. This guide covers various methods, troubleshooting tips, and best practices for managing your Python environment.
Pip is the standard package manager for Python. It allows you to install and manage additional libraries and dependencies that are not part of the Python standard library. If you're developing with Python on macOS or OS X, understanding how to properly install and use pip is fundamental. This article will walk you through the most common and recommended methods for getting pip up and running on your system, ensuring a smooth development workflow.
Understanding Python and Pip on macOS
macOS traditionally comes with a pre-installed version of Python (often Python 2.x). However, it's generally recommended to install a separate, newer version of Python (Python 3.x) for development purposes to avoid conflicts with system utilities that rely on the older Python 2.x. When you install Python 3.x using official installers or Homebrew, pip is usually included automatically. This section clarifies the relationship between Python versions and pip availability.
flowchart TD A[Start: macOS System] --> B{Python Installed?} B -- Yes, System Python 2.x --> C[Avoid using system Python for dev] B -- No / Yes, but need Python 3.x --> D[Install Python 3.x] D --> E{How to Install Python 3.x?} E -- Official Installer --> F[Pip 3 included automatically] E -- Homebrew --> G[Pip 3 included automatically] F --> H[Verify Pip Installation] G --> H C --> D H --> I[End: Pip Ready]
Decision flow for Python and Pip installation on macOS
Method 1: Installing Python 3 with Homebrew (Recommended)
Homebrew is a popular package manager for macOS that simplifies the installation of various software, including Python. This is often the preferred method for developers as it keeps your Python installation separate from the system's Python and makes managing packages straightforward. If you don't have Homebrew installed, you'll need to install it first.
1. Install Homebrew (if not already installed)
Open your Terminal application and paste the following command. Press Enter and follow the on-screen instructions. You might be prompted for your administrator password.
2. Install Python 3 using Homebrew
Once Homebrew is installed, you can install Python 3. This command will install the latest stable version of Python 3, which includes pip.
3. Verify Python and Pip Installation
After the installation completes, verify that both Python 3 and pip are correctly installed and accessible from your PATH. You should see the version numbers for both.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Command to install Homebrew
brew install python
Command to install Python 3 via Homebrew
python3 --version
pip3 --version
Verifying Python 3 and pip 3 versions
python3
and pip3
respectively. This helps avoid conflicts with the system's python
(Python 2.x) and pip
(if present).Method 2: Installing Python 3 via Official Installer
Another reliable way to install Python 3 and pip is by downloading the official installer directly from the Python website. This method is straightforward and ensures you get a complete, self-contained Python environment.
1. Download the Python Installer
Visit the official Python website (python.org) and navigate to the Downloads section. Download the latest stable macOS installer for Python 3.x (usually a .pkg
file).
2. Run the Installer
Locate the downloaded .pkg
file and double-click it to start the installation process. Follow the on-screen prompts, accepting the default options. The installer will automatically include pip.
3. Verify Python and Pip Installation
After the installation is complete, open your Terminal and verify the Python and pip versions. The installer typically adds Python 3 and pip 3 to your PATH.
python3 --version
pip3 --version
Verifying Python 3 and pip 3 after official installer
pip3
commands are not found, you might need to restart your Terminal or ensure that the Python installation directory is correctly added to your system's PATH environment variable. The installer usually handles this automatically.Upgrading Pip and Managing Packages
Once pip is installed, it's good practice to keep it updated to the latest version. You can also use pip to install, upgrade, and remove Python packages.
python3 -m pip install --upgrade pip
Upgrading pip to the latest version
pip3 install <package_name>
pip3 install requests
pip3 uninstall <package_name>
pip3 uninstall requests
pip3 list
Common pip commands for package management