1671

I spent most of the day yesterday searching for a clear answer for installing pip (package manager for Python). I can't find a good solution.

How do I install it?

0

21 Answers 21

3472

On Linux or MacOS:

python -m ensurepip --upgrade

If you want to install pip for Python 3, replace python with python3.

See https://pip.pypa.io/en/stable/installation/ for more details.

30
  • 26
    If you are behind a proxy, make sure http_proxy and https_proxy are set correctly, then use the '-E' option with sudo: sudo -E easy_install pip Commented Aug 4, 2014 at 20:10
  • 20
    Installed /Library/Python/2.7/site-packages/pip-6.0.6-py2.7.egg -- what about my python3 installation? Does this just mean that pip uses my python2 installation? Commented Jan 8, 2015 at 22:37
  • 51
    An extra warning: don't run this when a homebrew based python installed and occurs earlier in PATH (e.g. when you change /etc/paths): it would install pip with root credentials for the wrong python
    – acidjunk
    Commented Jan 7, 2016 at 13:56
  • 12
    Got error #notsoeasy Download error on pypi.python.org/simple: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found! No local packages or download links found for pip error: Could not find suitable distribution for Requirement.parse('pip')
    – htafoya
    Commented Apr 20, 2018 at 14:47
  • 9
    @htafoya I got the same error. This worked for me instead. curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && sudo python get-pip.py
    – user2975337
    Commented Apr 22, 2018 at 1:55
777

⚡️ TL;DR — One-line solution.

Run the following command for Python v2.7 (default on Mac as of 2021)

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py | python

Run the following command for Python v3

curl https://bootstrap.pypa.io/get-pip.py | python

Or the following if you have it installed as Python 3

curl https://bootstrap.pypa.io/get-pip.py | python3

Another GIF image you said? Here you go!

GIF install pip


The following used to work in 2019 and before

All you had to do was:

sudo easy_install pip

2019: ⚠️easy_install has been deprecated. Check Method #2 below for the preferred installation!

Details:

⚡️ OK, I read the solutions given above, but here's an easy solution to install pip.

The macOS comes with the Python environment installed. But to make sure that you have Python installed open the terminal and run the following command.

python --version

If this command returns a version number that means Python exists. This also means that you already have access to easy_install considering you are using macOS or OS X.

ℹ️ Now, all you have to do is run the following command.

sudo easy_install pip

After that, pip will be installed and you'll be able to use it for installing other packages.

P.S. I ended up blogging a post about it. QuickTip: How Do I Install pip on macOS or OS X?


✅ Method #2: Two line solution

easy_install has been deprecated. Please use get-pip.py instead.

Download and install PIP

curl https://bootstrap.pypa.io/get-pip.py | python
16
  • 5
    ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip' Consider using the --user option or check the permissions.
    – 2540625
    Commented May 19, 2019 at 21:06
  • 1
    Try usingsudo Commented May 22, 2019 at 0:38
  • 3
    After trying out python get-pip.py I get ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-19.1.1.dist-info/RECORD' Consider using the --user option or check the permissions.
    – Jonas
    Commented May 23, 2019 at 8:20
  • 1
    Here's a nice one-liner: curl https://bootstrap.pypa.io/get-pip.py | python
    – Alex V
    Commented Dec 25, 2019 at 16:09
  • 2
    what did you use for GIF?
    – Nishchit
    Commented Jul 5, 2020 at 15:51
553

I'm surprised no-one has mentioned this - since 2013, python itself is capable of installing pip, no external commands (and no internet connection) required.

sudo -H python -m ensurepip

This will create a similar install to what easy_install would.

12
  • 3
    Perfect! My system could not locate easy-install, so the other solutions did not work.
    – buzzard51
    Commented Mar 26, 2017 at 17:54
  • 1
    This worked from behind a firewall where the others failed. Thanks!
    – Floris
    Commented Jun 28, 2017 at 23:18
  • 7
    This helps if you have multiple versions of python, and need a specific one to get pip.
    – Teepeemm
    Commented Feb 6, 2018 at 2:53
  • 2
    @user3.1415927 you could use /path/to/your/python -m pip <command>
    – felixphew
    Commented Apr 16, 2018 at 3:31
  • 6
    Best solution, worked like charm on MacOS. easy_install was giving download errors.
    – eXc
    Commented May 14, 2018 at 20:09
534

You can install it through Homebrew on OS X. Why would you install Python with Homebrew?

The version of Python that ships with OS X is great for learning but it’s not good for development. The version shipped with OS X may be out of date from the official current Python release, which is considered the stable production version. (source)

Homebrew is something of a package manager for OS X. Find more details on the Homebrew page. Once Homebrew is installed, run the following to install the latest Python, Pip & Setuptools:

brew install python
20
  • 19
    Note that if you use homebrew, then you end up using your own python, not the system one. This is the road to hell if you want to use wxpython ... Commented Nov 10, 2013 at 3:09
  • 3
    I like this solution as "sudo" is not required. Let's not stuff around with the system's python. Commented Apr 17, 2015 at 5:30
  • 4
    Installing python with homebrew also installs pip. Everything is locally installed and doesn't require sudo. Commented Oct 4, 2015 at 17:57
  • 91
    If you brew-install Python, but pip is still not in your path, you might need to re-link, like this brew unlink python && brew link python Commented Aug 17, 2017 at 2:25
  • 6
    In my case, after installing python 2 and 3 I noticed that there was no default python symlink in /usr/local/bin (thus python still went to system python). A quick symlink in /usr/local/bin to the brewed python of choice did the trick, but keep that in mind if you hope to have a homebrew-installed python when you type python. Beyond that, python2 / pip2 (and/or python3 / pip3) work accordingly for the latest brew-installed python versions. Commented Nov 22, 2017 at 8:12
141

On Mac:

  1. Install easy_install

    curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python
    
  2. Install pip

    sudo easy_install pip
    
  3. Now, you could install external modules. For example

    pip install regex   # This is only an example for installing other modules
    
6
  • Above solutions all yielded DistributionNotFound exceptions. This worked perfectly.
    – stuckj
    Commented Oct 20, 2015 at 21:15
  • I had to restart the terminal after easy_install install, and i had to run SUDO on pip install something.. But after that, works perfectly Commented May 10, 2016 at 23:55
  • 5
    The latest OSX is already bundled with easy_install and calling curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python will break your setup! Don't install easy_setup if you already have it, I've spent an hour to repair my setup after this command (thanks to stackoverflow.com/questions/6012246/…). Commented Nov 25, 2016 at 9:16
  • 1
    Downvoting for piping curl directly into an interpreter... common as this practice is, it's something I don't like the security implications of. (Also, I think there are better answers for this question.)
    – lindes
    Commented Dec 23, 2016 at 19:54
  • These are also the official instructions from amazon too - docs.aws.amazon.com/cli/latest/userguide/cli-install-macos.html
    – chrismarx
    Commented Jun 29, 2018 at 15:02
125

macOS v10.15 (Catalina)

Install Homebrew:

mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew

Add the path:

sudo nano  ~/.bash_profile

Add this line:

export PATH="$HOME/homebrew/bin:$PATH"

Install Python 3:

brew install python

This Python (v3) also installs pip3. In order to use only 'pip', add an alias:

sudo nano  ~/.bash_profile

Add this line:

alias pip=pip3

macOS v10.14 (Mojave)

macOS comes with Python 2, but not with pip. Anyway, it's better to manage it with Homebrew. You must install it before.

Install Python 2:

brew install python

WARNING: for a modern macOS (2019) this can install Python 3, and for Python 2 you really need to do: brew install python@2

Install Python 3:

brew install python3

Python 3

If you install Python 3, pip will be installed automatically.

brew install python3

As of 2019, now to use pip version 3, use pip3. Or you can execute: python3, to use version 3. When you install packages with pip3 they will be separated from Python 2.

For older versions: You need only to upgrade pip, but before that you need create a virtual environment to work with Python 3. You can use a project folder or any folder:

python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip

Check the versions:

pip -V
python --version

After 2019:

pip3 -V
python3 --version

To deactivate the environment:

deactivate
7
  • For me, sudo python get_pip.py worked well, cause on OS X python is already installed! Commented Dec 17, 2016 at 20:10
  • This may be an option to go with if you want to use a newer version of Python since Macs default install of Python is 2.7.x. You would do this by changing step 2 above to python3 instead of python. Additional note, the brew install of python will also install pip, and provide info on upgrading/uisng pip. Commented Dec 18, 2016 at 16:52
  • @DeliciaBrummitt i've corrected my answer in accordance to your suggestion, and I've added a new block for python3
    – stackdave
    Commented Dec 25, 2016 at 2:09
  • curl -O https://bootstrap.pypa.io/get-pip.py | sudo python3 get-pip.py for Python3 on El Capitan.
    – marw
    Commented Jan 9, 2017 at 19:58
  • 11
    My pip is called pip3
    – Evan Moran
    Commented Aug 19, 2018 at 17:03
90

pip is available on OS X via easy_install.

Open a terminal and type:

sudo easy_install pip

When prompted for a password, enter your normal login password. After the installation has completed, you should be able to use pip as expected.

Note: this works for other Python packages as well

3
  • This one line fixed pip on my Mac when all I got before was some kind of DistributionNotFound exception trying to install something via pip. (Mac OS X 10.10.4, Python 2.7) Commented Jul 3, 2015 at 20:59
  • 2
    I had to also then run pip install --upgrade pip
    – thorr18
    Commented Jan 20, 2016 at 4:48
  • Is pip depended on python version? I installed python3, but this command seems to be using python2. pip is installed successfully, though.
    – Felix
    Commented Jun 19, 2017 at 7:46
86

The simplest solution is to follow the installation instruction from pip's home site.

Basically, this consists of:

  • downloading get-pip.py. Be sure to do this by following a trusted link since you will have to run the script as root.
  • call sudo python get-pip.py

The main advantage of that solution is that it install pip for the Python version that has been used to run get-pip.py, which means that if you use the default OS X installation of Python to run get-pip.py, you will install pip for the Python install from the system.

Most solutions that use a package manager (Homebrew or MacPorts) on OS X create a redundant installation of Python in the environment of the package manager which can create inconsistencies in your system since, depending on what you are doing, you may call one installation of Python instead of another.

5
  • I have a second brew installed python, but I am trying to install pip on my original /usr/bin mac python. Do you know how I can access pip for that installation? I used /usr/bin/python to install pip, but pip wasn't in /usr/bin/.
    – Wesley
    Commented Jun 26, 2014 at 16:28
  • 1
    @Wesley How did you get that second installation? If you are using a python version manager there should be an option to set the python version you want and then you should be able to install pip for that specific version via the method above.
    – j--
    Commented Feb 22, 2015 at 8:05
  • 1
    It is unsecure, because you run get-pip.py under sudo, but you can't guarantee that you downloaded proper get-pip.py until you know checksum. More on this: stackoverflow.com/questions/34587473/… Commented Jan 4, 2016 at 13:06
  • 2
    It looks like the linked page has moved to pip.pypa.io/en/stable/installing which mentions "Warning! Be cautious if you're using a Python install that's managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state." Commented Aug 9, 2017 at 19:13
  • 2
    That warning is confusing to me because using the git-pip.py script to install pip for Apple's stock python is the main use case for the script existing vs just installing python via homebrew. Commented Aug 9, 2017 at 19:14
48

For those who have both Python 2 and Python 3 installed, here's the solution:

python2.7 -m ensurepip --default-pip

Additionally, if you want to install pip for Python 3.6:

wget https://bootstrap.pypa.io/get-pip.py
sudo python3.6 get-pip.py
3
  • 4
    this needs to be the accepted answer for recent pythons, so that people stop doing the old silly stuff
    – ccpizza
    Commented Oct 6, 2017 at 6:24
  • python get-pip.py
    – DocJ457
    Commented Dec 28, 2018 at 4:49
  • Thank you so much and this is working for me. I got a old mac and upgraded the system. I was try to install some pip packages with python 2 pip and this help me out. to whom not sure how to check, pip -V to check the pip version and pip freeze to check the installed package.
    – Wei Jing
    Commented Aug 23, 2021 at 4:25
44

Installing a separate copy of Python is a popular option, even though Python already comes with macOS. You take on the responsibility to make sure you're using the copy of Python you intend. But, the benefits are having the latest Python release and some protection from hosing your system if things go badly wrong.

To install Python using HomeBrew:

brew update
brew install python # or brew install python3

Now confirm that we're working with our newly installed Python:

ls -lh `which python`

...should show a symbolic link to a path with "Cellar" in it like:

lrwxr-xr-x  1 chris  admin    35B Dec  2 13:40 /usr/local/bin/python -> ../Cellar/python/2.7.8_2/bin/python

Pip should be installed along with Python. You might want to upgrade it by typing:

pip install --upgrade pip

Now you're ready to install any of the 50,000+ packages on PyPI.

Other Notes

Formerly, I've used get-pip.py to install pip. But, the docs warn that get-pip.py does not coordinate with package managers and may leave your system in an inconsistent state. Anyway, there's no need, given that pip is now included with Python as of 2.7.9.

Note that pip isn't the only package manager for Python. There's also easy_install. It's no good to mix the two, so don't do it.

Finally, if you have both Python 2 and 3 installed, pip will point to whichever Python you installed last. Get in the habit of explicitly using either pip2 or pip3, so you're sure which Python is getting the new library.

Happy hacking!

2
  • 1
    actually, python symlinks to python2, and python3 symlinks to python3... regardless of which was installed last. Commented Jan 17, 2017 at 3:34
  • 1
    This page from Homebrew docs explains which version each command points to: docs.brew.sh/Homebrew-and-Python Commented Oct 31, 2018 at 12:48
31

You should install Homebrew (executable brew) first:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then brew install Python

brew install python

Then pip will work.

3
  • 9
    But - you have not installed pip in the system python in this case, rather you have installed a new python and pip along with it. Then you will be into all sorts of strife trying to use wxpython... Commented Nov 10, 2013 at 3:10
  • for me brew didn't set the symlinks for python and pip, ln -s -f /usr/local/bin/pip3 /usr/local/bin/pip Commented Apr 24, 2023 at 10:05
  • You can try running these two codes 1. Open the Terminal app via Launchpad. | curl bootstrap.pypa.io/get-pip.py -o get-pip.py | python3 get-pip.py Commented Jul 6, 2023 at 3:30
30

Download this file: get-pip.py

Then simply type

sudo python get-pip.py

Make sure you are in the same directory as get-pip.py or you supply the correct path for that file.

For details, you can visit: Installation - pip documentation

Or, http://thegauraw-blog-blog.tumblr.com/post/47601704154/how-to-install-pip-in-both-windows-ubuntu-easiest-way

2
  • This worked for me thanks. Only one small change, I needed to use python3 so: sudo python3 get-pip.py Commented Apr 14, 2021 at 9:39
  • The second link is broken ("Not Found. The URL you requested could not be found."). Commented Sep 17, 2022 at 15:56
28

On the recent version (from Yosemite or El Capitan I believe... at least from Sierra onward), you need to run brew postinstall python3 after brew install python3 if you use Homebrew.

So,

brew install python3 # this only installs python
brew postinstall python3 # this installs pip

Homebrew version after 1.5

According to the official Homebrew page:

On 1st March 2018 the python formula will be upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link --force). We will maintain python2, python3 and python@3 aliases.

So to install Python 3, run the following command:

brew install python3

Then, the pip is installed automatically, and you can install any package by pip install <package>.

5
  • 7
    Didn't work for me. I'm on Sierra. After doing those commands, it looked successful, but then -bash: pip: command not found. What did work for me was the top answer: sudo easy_install pip
    – iamse7en
    Commented Dec 1, 2017 at 19:59
  • @iamse7en Did you restart Terminal or open another tab? What is the log after the postinstall command?
    – Blaszard
    Commented Dec 2, 2017 at 12:46
  • FWIW - I also had the pip: command not found message. I did try to open a new tab in iTerm and had the same message. No errors on either brew command. Commented Dec 19, 2017 at 3:34
  • I guess this will install python 3, and not pip.
    – Karthik RP
    Commented Mar 8, 2018 at 8:46
  • 8
    for those where it didn't work, look for pip3 but not "pip" and maybe create an alias
    – eMerzh
    Commented Apr 20, 2018 at 19:32
21

If you want "pip3" you can do the ff:

via brew: brew install python3

enter image description here

then you can execute

pip3 <command> [options]

1
14
sudo port install py27-pip

Then update your PATH to include the py27-pip bin directory (you can add this in ~/.bash_profile:

PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH

pip will be available in a new terminal window.

3
  • 1
    port is not installed by default
    – pmagunia
    Commented Dec 1, 2015 at 21:08
  • The default shell was changed from Bash to Z shell in macOS v10.15 (Catalina, 2019). Commented Sep 17, 2022 at 16:20
  • this of course assumes MacPorts is installed; also, when using MacPorts, I'm using the (newer) version of bash (v5.2) that can be installed via port rather than the outdated version that comes w/ macOS (v3.2), assuming for whatever one doesn't want to run the default macOS shell (zsh) macports.org/install.php
    – michael
    Commented Jan 12, 2023 at 10:15
12

Install Python 3 first, and then use pip3 to install packages.

brew install python

Python 3 will be installed, and pip is shipped with it. To use pip to install some package, run the following

pip3 install package

Notice it's pip3 because you want to use Python 3.

12

To install or upgrade pip, download get-pip.py from Installation - pip documentation

Then run the following:

sudo python get-pip.py

For example:

sudo python Desktop/get-pip.py

Password:
  Downloading/unpacking pip
  Downloading pip-1.5.2-py2.py3-none-any.whl (1.2MB): 1.2MB downloaded
Installing collected packages: pip
Successfully installed pip
Cleaning up...
sudo pip install pymongo

Password:
Downloading/unpacking pymongo
  Downloading pymongo-2.6.3.tar.gz (324kB): 324kB downloaded
  Running setup.py (path:/private/var/folders/0c/jb79t3bx7cz6h7p71ydhwb_m0000gn/T/pip_build_goker/pymongo/setup.py) egg_info for package pymongo

Installing collected packages: pymongo
...
2
  • 1
    Yes, but there are simpler methods Commented Apr 10, 2014 at 6:24
  • get-pip.py is about as simple as it gets Commented Jan 17, 2017 at 3:35
9

Install without the need for sudo

If you want to install pip without the need for sudo, which is always frustrating when trying to install packages globally, install pip in your local folder /usr/local like this:

curl https://bootstrap.pypa.io/get-pip.py > get-pip.py
python get-pip.py --prefix=/usr/local/

and then:

pip install <package-of-choice> without sudo

2
8

Download the Python setup tools from the PyPI website:

Use the tar file.

Once you download, go to the downloaded folder and run

python setup.py install

Once you do that, you will have easy_install.

Use the below then to install pip:

sudo easy_install pip
1
  • If you download the Mac installer packages from python.org, then pip is bundled in the installation. No need to run setup tools anymore.
    – benwiggy
    Commented Apr 21, 2020 at 9:02
4

Somehow easy install doesn't work on my old Mac (10.8 (Mountain Lion)). This solves my problem:

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

If you do not have wget, just open the URL in the browser, https://bootstrap.pypa.io/get-pip.py, and then save as get-pip.py.

-5

I recommend Anaconda to you. It's the leading open data science platform powered by Python. There are many basic packages installed. Anaconda (conda) comes with its own installation of pip.

5
  • 6
    Not related to the question
    – Don P
    Commented Dec 6, 2016 at 0:25
  • 3
    @DonnyP Actually, this suggestion addresses the question and would expeditiously solve the original problem as it comes with pip. This answer should be promoted and encouraged.
    – pylang
    Commented Jan 18, 2017 at 20:32
  • 1
    this is not an answer this is an advertisement. If I'm mistaken the author should provide more details on how this addresses the question. Commented Aug 14, 2017 at 3:30
  • 2
    The question was how to install pip. If you recommend a product that already includes pip, then your answer (or suggestion) is not related to the question. Commented Aug 3, 2019 at 2:39
  • 2
    This is the correct answer. conda comes with pip installed already. It is preferable to just use a conda installation on your Mac than to use the other methods described that mess with direct system installations. Especially when it comes to Python, installing things with a bare-pip is a very bad idea. You should be using the pip that comes with conda instead to correctly isolate your package environments. Commented Jan 21, 2020 at 18:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.