How do I install pip on macOS or OS X?
Install pip swiftly on macOS with one easy command:
python3 -m ensurepip --upgrade
This command uses the Python 3’s built-in ensurepip module to install or update pip directly. For a secure and up-to-date pip installation, always opt for the python3 command. This is particularly important when dealing with Python 3 specifics.
Checking out the pip scene
Is pip already there?
Ensure pip does not already exist on your machine:
pip --version
or
pip3 --version
If you see a version number, congratulations – you already have pip! In case pip isn’t installed yet or an upgrade is on the cards, stick around!
Making pip happen with ensurepip
For Python versions 3.4 and above, we have the ensurepip module to install pip. Run the command:
python3 -m ensurepip --upgrade
To keep things manageable, the above command also upgrades pip. For legacy versions (i.e., Python 2), replace python3 with just python.
Homebrew - a friend indeed!
We highly recommend using Homebrew to manage your Python and pip installations:
brew install python # Grabs a cold one with the Pythons
The above command installs both Python and pip, and ensures these applications are up-to-date, including Python packaging tools like setuptools.
Dodging installation woes
Caught between Python versions
Conflicting Python versions causing trouble? Point to the Homebrew version of Python to bypass default or outdated Python installations:
/usr/local/bin/python3 -m ensurepip --upgrade # Only trust the locals
Permission pitfalls
Encountering permission issues during the pip installation? Apply sudo with caution:
sudo -H python3 -m ensurepip --upgrade # "look at me. I'm the admin now."
Note: Always be aware of associated security risks when using sudo.
Departing from easy_install
easy_install was historically used to install pip. However, it's now deprecated. Favor modern methods like ensurepip or Homebrew which are more secure and reliable.
Was this article helpful?