How to Install PIP on a Mac

Make everything easier with PIP for Python

The Python Package Index, or PyPI

 The Python Software Foundation

In Python, using Python packages published by other developers in your own project one thing that will make your life easier. The Python Package Index, or PyPI, is a huge repository of code you can use. Learn how to get you started with PyPI and its installer program, PIP (Package Installer for Python).

These instructions should work on any macOS version supported by the current Python installer, which includes v10.6+ (Snow Leopard) for the 32-bit installer, and v10.9 (Mavericks) for the 64-bit only version of the current installer (v3.7 at the time of writing). With the next release, the 32-bit installer will be removed, so if you use an older-generation mac, you'll be limited to Python 3.7 until you upgrade your machine.

How to Install PIP on macOS

PIP is the default package installer and was recently added to to the core distribution of Python. This means to install PIP we need to install Python.

macOS comes with Python v2.7 pre-installed, but you should instead use the newer version v3.7. The only reason to continue using v2.7 is to support older, existing applications. Luckily, if you're just getting started, you don't have any of these.

Python installation is a standard .PKG-based affair. To get it up and running, take the following steps:

  1. First, head on over to the Python website and grab the latest release. Unless you're on an older machine and have to use a previous version of macOS for some reason, download the 64-bit installer file.

    Python Installer for macOS Downloads
  2. This is the standard macOS .PKG format, so you can just click the installer file to kick things off.

  3. The first screen will provide some info on the install, click Continue to move along.

    Introductory Screen for the Python macOS Installer
  4. Click Continue on the following page as well, which lets you know the project will stop providing support for 32-bit installers from v3.8 onward.

    README File for the Python macOS Installer
  5. The next screen asks you to accept the license for Python. Click Continue, then click Agree.

    License Screen for the Python macOS Installer
  6. You'll need to select a destination for the install on the following screen. You can click Install to place it on your main drive, or click Customize if you have somewhere else in mind. You'll also need to enter your password to continue.

    Install Location Screen in the Python macOS Installer
  7. Now the installer will start copying the files.

    Progress Screen in the Python macOS Installer
  8. Once the installation is finished, the app's folder will open in Finder.

Examining the Python Install on macOS

The installation contains a few items, as follows:

  • Two .RTF files: Once contains the License; the other the ReadMe file.
  • Two .COMMAND files: These are there to help perform some configuration. The Install Certificates.command file will set up some SSL certificates, and the Update Shell Profile.command file will help if you have trouble using Python 3, and find that you're always being directed to Python 2.
  • IDLE app: An integrated development environment specifically for Python.
  • Python Launcher: Helps you to configure some settings related to launching Python scripts.

How to Confirm Python is Working on macOS

Before you can use Python, it's best to confirm your Python installation is working correctly.

  1. Try the following command in Terminal:

    python --version
    Python 3.7.4
  2. If you want to further confirm things, try running a simple Python script. Enter (or paste) the following code into an empty text file and naming it "hello-world.py":

    print ("Hello World!")
  3. Now, at the command prompt, run the following:

python \path\to\hello-world.py
Hello World!

How to Use Python's PIP on macOS

We know now Python is working, and we can move on to using PIP.

Fortunately, there's nothing to do here: PIP comes installed out-of-the-box on newer versions of Python. That said, you should familiarize yourself with it.

  1. Using the following command in Terminal will give you an overview of what PIP's all about:

    pip --help
  2. The first thing you'll probably want to do is look for a package you can use, and pip search is what you need for that. It will search the Python Package Index (PyPI) for your search term.

    Suppose we want to create our Python application to save passwords. macOS already has a great mechanism for this: Keychain. The following command will show a list of all the packages in PyPI with the keyword "keychain":

    pip search keychain
  3. In the results, there's a package called macos-keychain, which is exactly what we're looking for. So, instead of coding things like password entries, encryption, and hooking into system events, we can just download this and integrate it to our needs. You can install a package with the following command:

    pip install macos-keychain
    Searching PyPI with PIP in macOS Terminal
  4. Unfortunately, updating all installed packages isn't as easy as updating Linux distributions. You need to do so for each package when you see it's out of date. Use the following command:

    pip install macos-keychain --upgrade
  5. Finally, removing a package is as easy as:

pip uninstall macos-keychain