1673

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?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
The System
  • 16,771
  • 3
  • 10
  • 3

21 Answers21

3362

UPDATE (Jan 2019):

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


Old answer:

easy_install pip

If you need admin privileges to run this, try:

sudo easy_install pip
Scott Tesler
  • 38,148
  • 4
  • 23
  • 20
  • 25
    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 – Neil Schaper Aug 04 '14 at 20:10
  • 18
    `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? – temporary_user_name Jan 08 '15 at 22:37
  • If you're not running as admin (arguably you shouldn't) you'll need to do su admin_account_name and then provide admin account pw when prompted. After that you can run sudo easy_install pip. – John Faughnan May 21 '15 at 02:35
  • 49
    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 Jan 07 '16 at 13:56
  • 2
    @acidjunk What do you do if you have a homebrew based python installed and occurring earlier in PATH? – TheEnvironmentalist Dec 06 '16 at 06:55
  • 1
    @TheEnvironmentalist a home brew python already has pip. If you want to add pip to the Mac OS variant you could invoke the correct easy_install by using it's full path: sudo /usr/bin/easy_install pip – acidjunk Dec 06 '16 at 18:28
  • 2
    Never sudo install a package for any language. This is insecure and will ruin your life later as more and more packages need sudo permissions. – Andy Ray Jul 31 '17 at 01:22
  • 1
    This is only a partial solution. Some pip packages will try to overwrite files that are readonly in the macOS stock Python installation and therefore fail to install. This is a case where you are better off installing a separate version of Python and using it exclusively - whether via Homebrew, MacPorts, pyenv, virtualenv, or whatever. – Mark Reed Aug 24 '17 at 17:21
  • 1
    @acidjunk is correct. In ML/DS you will have python2 and python3. MacOS default python2 is in `/usr/bin` so that's why you need to do `sudo /usr/bin/easy_install pip`. python3 should be installed in `/usr/local/bin`. This means python versions will never conflict with each other. So whenever you use `python` or `pip` this will only install python2 versions. Whenever you use `python3` or `pip3` this will only install python3 versions. As a bonus, when you install jupyter in python2/3 virtualenvs, jupyter will automatically use the correct kernel. – Edison Sep 19 '17 at 21:21
  • 1
    Worked without sudo for me. – Daniel Springer Oct 24 '17 at 19:56
  • 1
    You know what would be even easier? brew install pip. Since brew is the most popular package manager for OSX and people will generally try to install through that. For example, when I needed pip just now I just went straight to brew and typed in the above command assuming that it would be there. – Ian Nov 08 '17 at 14:02
  • https://stackoverflow.com/questions/21055859/what-are-the-risks-of-running-sudo-pip - there are some risks to installing using sudo – Joshua Dance Dec 21 '17 at 05:18
  • 11
    Got error #notsoeasy Download error on https://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 Apr 20 '18 at 14:47
  • 6
    @htafoya I got the same error. [This worked](https://pip.readthedocs.io/en/stable/installing/) for me instead. `curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && sudo python get-pip.py` –  Apr 22 '18 at 01:55
  • 4
    Download error on https://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') – Edward Falk Apr 26 '18 at 04:43
  • 1
    I get "error: Could not find suitable distribution for Requirement.parse('pip')" – Maxim Sep 12 '18 at 19:41
  • Couldn't find index page for 'pip' (maybe misspelled?) - No local packages or download links found for pip - error: Could not find suitable distribution for Requirement.parse('pip') – Ben Oct 18 '18 at 07:20
  • Same Could not find suitable distribution for Requirement.parse('pip') error – axel Nov 30 '18 at 10:44
  • 2
    `sudo easy_install pip` work for me, `get-pip.py` don't – Jason Zhou Mar 08 '19 at 09:51
  • this answer needs to be updated. the correct answer is now get-pip.py. its quite likely that using the older method still works particularly if other versions of py (<3.7) exist in the environment. – Anonymous Type Aug 03 '19 at 02:28
  • Easiest way to install pip after easy_install got deprecated: 1. curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 2. python get-pip.py – Shagun Pruthi Sep 12 '19 at 12:24
  • Here's a nice one-liner: `curl https://bootstrap.pypa.io/get-pip.py | python` – Alex V Dec 25 '19 at 16:08
  • where does the pip binary go after installing with get-pip.py? I don't see it in my PATH anywhere. – dinesh ygv May 15 '20 at 13:55
  • Or `curl -L get-pip.io | sudo -H python`. – Jon-Eric Jun 28 '20 at 00:57
  • Is there a Reason why this script consists of 1.7MB of compressed data? Smells fishy to say the least. – j4k3 Oct 24 '20 at 13:22
639

⚡️ TL;DR — One line solution.

All you have to do is:

sudo easy_install pip

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

Details:

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

MacOS comes with Python 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. Which also means that you already have access to easy_install considering you are using macOS/OSX.

ℹ️ 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.

Let me know if you have any problems installing pip this way.

Cheers!

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


UPDATE (Jan 2019): METHOD #2: Two line solution —

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

First of all download the get-pip file

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

Now run this file to install pip

python get-pip.py

That should do it.

Another gif you said? Here ya go!

stackdave
  • 5,351
  • 8
  • 32
  • 55
Ahmad Awais
  • 23,458
  • 4
  • 66
  • 52
  • 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 May 19 '19 at 21:06
  • 1
    Try using`sudo` – Ahmad Awais May 22 '19 at 00:38
  • 1
    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 May 23 '19 at 08:20
  • I just tried, http://on.ahmda.ws/424d72 — it's working as expected. Are you using the second up to date method? – Ahmad Awais May 24 '19 at 12:45
  • After `curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py`, I get this `curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to bootstrap.pypa.io:443` any ideas ? @AhmadAwais – Jony Jun 14 '19 at 14:58
  • Looks like an SSL error. Can you try running the same without `https` and with `http`? – Ahmad Awais Jun 15 '19 at 03:46
  • `ERROR: Could not install packages due to an EnvironmentError` – pkamb Dec 13 '19 at 00:38
  • 1
    Here's a nice one-liner: `curl https://bootstrap.pypa.io/get-pip.py | python` – Alex V Dec 25 '19 at 16:09
  • Don't use `sudo` for `python` on `macos`! First make sure you own it (`$ sudo chown $(whoami) /usr/local`), then use `/usr/local` for all python programs, e.g. installing `pip`: `/usr/local/bin/python3 get-pip.py --prefix=/usr/local --upgrade` – jalanb Feb 08 '20 at 19:08
  • And don't let Homebrew mess up `/usr/local`: tell it to use `/opt/local` or elsewhere – jalanb Feb 08 '20 at 19:10
  • 2
    what did you use for GIF? – Nishchit Jul 05 '20 at 15:51
  • 1
    ^For that check out https://AhmadAwais.com/uses page. – Ahmad Awais Jul 06 '20 at 16:42
  • Could we consider updating this in the light of python2 being deprecated (but still present) on BigSur and python3 being an entirely different command? – yeliabsalohcin Mar 25 '21 at 09:32
  • The updated method I listed still works for me though? – Ahmad Awais Apr 23 '21 at 23:42
  • And note: the "system" python on MacOs is STILL python2. If you want to install a module for THAT python, you need `curl https://bootstrap.pypa.io/pip/2.7/get-pip.py | python`. (because the other one is for python3!) – GhostCat Apr 28 '21 at 06:41
508

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
Pete
  • 9,450
  • 7
  • 50
  • 57
Leigh
  • 10,820
  • 4
  • 25
  • 35
  • Pip isn't running even after following your steps? I restarted the shell but still no avail. – discipulus Sep 17 '13 at 13:51
  • 1
    Have you made sure that you've got ```/usr/local/bin``` in your PATH? Try running ```/usr/local/bin/pip``` which is a full path to the pip program. – Leigh Sep 18 '13 at 06:44
  • 2
    The folder /usr/local/bin/pip was in path but pip wasn't running. I deleted the folder and reinstalled it and now it runs. Thanks !! – discipulus Sep 19 '13 at 08:58
  • 1
    how you deal with two versions of python installed ? if you want to install a module via pip, this will install it only in the brew version, hence, if you run something like python script.py which requires that module, you will get an error... – alexserver Nov 01 '13 at 05:13
  • 1
    Mac OS X 10.9 has python 2.7.5 by default – chaim Nov 04 '13 at 19:21
  • 17
    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 ... – GreenAsJade Nov 10 '13 at 03:09
  • @GreenAsJade What is the solution then? – Jorge Bucaran Feb 22 '15 at 08:04
  • 1
    @JorgeBucaran pretty sure you can ensure the right paths are in $PATH, and you will point to the correct version of python you intend to use. i.e. /usr/local/bin comes before /usr/bin. If you've already got a version of python on mac osx, then use the `easy_install` method mentioned – Danny Mar 30 '15 at 16:51
  • @JorgeBucaran ... sorry I only just saw your question! As per the most accepted answer, easy_install pip with sudo. – GreenAsJade Apr 14 '15 at 07:09
  • 3
    I like this solution as "sudo" is not required. Let's not stuff around with the system's python. – justrhysism Apr 17 '15 at 05:30
  • 3
    Installing python with homebrew also installs pip. Everything is locally installed and doesn't require `sudo`. – joshlsullivan Oct 04 '15 at 17:57
  • Yes, this answer, plus I had to do `pip install --upgrade pip` – Kirby Mar 01 '16 at 23:20
  • It is the best way to use `pip`. Installing package with `sudo` when `pip` is installed with `easy_install` cases problems. – Hamid Rohani May 05 '16 at 20:40
  • 86
    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` – Christian Long Aug 17 '17 at 02:25
  • 3
    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. – MartyMacGyver Nov 22 '17 at 08:12
  • 2
    brew update && brew reinstall python@2 has worked for me recently – David Odhiambo Jan 10 '19 at 02:37
  • 1
    Homebrew is a serious security problem. The default install opens /usr/local/ to any malicious program that happens onto your account. Basically you are back to the (non) security of windows 3.1. /usr/local/bin is first in your path thus a malicious program can replace trusted system utilities without you noticing. – Samuel Åslund Apr 26 '19 at 21:25
  • 2
    Still no `pip` symlink after `brew link python`, but do have `pip3`. Are we expected to make the symlink manually? – Trejkaz Dec 11 '19 at 23:08
  • after brew install python ,pip3 will be installed. Set alias for pip to pip3 and you should update pip at once, by this command:pip install --upgrade pip --user – Allen Mar 26 '21 at 15:24
497

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.

felixphew
  • 5,353
  • 2
  • 16
  • 32
  • 3
    Perfect! My system could not locate easy-install, so the other solutions did not work. – buzzard51 Mar 26 '17 at 17:54
  • 1
    This worked from behind a firewall where the others failed. Thanks! – Floris Jun 28 '17 at 23:18
  • sudo -H is better in this case – Matt Sephton Jan 30 '18 at 18:47
  • @MattSephton you're right, but I wouldn't be worrying about the cache for this command - when run on python 2.7 it downloads pip 6.1, which will definitely need to be updated. – felixphew Jan 30 '18 at 19:54
  • I'm confused, `sudo -H` has nothing to do with the cache? it's a security policy directive. – Matt Sephton Feb 01 '18 at 00:24
  • 1
    @MattSephton the reason -H is necessary when using `pip` (as far as I understand) is to ensure the right user owns the cache directory. – felixphew Feb 01 '18 at 04:53
  • 7
    This helps if you have multiple versions of python, and need a specific one to get pip. – Teepeemm Feb 06 '18 at 02:53
  • 1
    @Teepeemm, how can I then target the proper pip installation to use pip for subsequent package installations? – user3.1415927 Apr 16 '18 at 03:30
  • 2
    @user3.1415927 you could use `/path/to/your/python -m pip ` – felixphew Apr 16 '18 at 03:31
  • 5
    Best solution, worked like charm on MacOS. easy_install was giving download errors. – eXc May 14 '18 at 20:09
  • Not anymore... `$ sudo python -m ensurepip Password: The directory '/Users/jdoe/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/Users/jdoe/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.` – John Greene Mar 20 '19 at 22:21
  • how to undo this? – sekmo Jun 20 '19 at 17:00
137

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
    
artburkart
  • 1,590
  • 1
  • 17
  • 26
Pavan
  • 2,427
  • 4
  • 15
  • 18
  • Above solutions all yielded DistributionNotFound exceptions. This worked perfectly. – stuckj Oct 20 '15 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 – Sindri Þór May 10 '16 at 23:55
  • 4
    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 http://stackoverflow.com/questions/6012246/why-is-python-easy-install-not-working-on-my-mac). – Sergiy Sokolenko Nov 25 '16 at 09: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 Dec 23 '16 at 19:54
  • These are also the official instructions from amazon too - https://docs.aws.amazon.com/cli/latest/userguide/cli-install-macos.html – chrismarx Jun 29 '18 at 15:02
  • Get "ImportError: cannot import name ContextualZipFile" in step 2. Please use "sudo -H python -m ensurepip" instead. – YH_WU Mar 24 '20 at 23:51
106

UPDATED 2020 August: MacOs Cataline

Install homebrew

https://docs.brew.sh/Installation

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 python3:

brew install python

This python (v3) install pip3, in order to use only 'pip' , add an alias:

sudo nano  ~/.bash_profile
Add this line:
alias pip=pip3

UPDATED 2019 October: MacOs Mojave

MacOS comes with python2, but not with pip. Anyway, it's better to manage it with homebrew, you must install it before:

https://docs.brew.sh/Installation

Install python2:

brew install python

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

Install python3:

brew install python3

UPDATE: Python 3

If you install python3, pip will be installed automatically.

brew install python3

NEW 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 python2.

OLD: 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

NEW 2019:
pip3 -V
python3 --version

To deactivate the environment:

$ deactivate
stackdave
  • 5,351
  • 8
  • 32
  • 55
  • For me, `sudo python get_pip.py` worked well, cause on OS X python is already installed! – Abhishek Ghosh Dec 17 '16 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. – Delicia Brummitt Dec 18 '16 at 16:52
  • @DeliciaBrummitt i've corrected my answer in accordance to your suggestion, and I've added a new block for python3 – stackdave Dec 25 '16 at 02:09
  • `curl -O https://bootstrap.pypa.io/get-pip.py | sudo python3 get-pip.py` for Python3 on El Capitan. – marw Jan 09 '17 at 19:58
  • 7
    My pip is called `pip3` – Evan Moran Aug 19 '18 at 17:03
  • Now installing python2 is `brew install python@2` and `brew install python` installs python3 – mmacvicar Oct 30 '19 at 04:44
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 too

Shirkrin
  • 3,827
  • 1
  • 25
  • 33
user3627034
  • 1,017
  • 7
  • 8
  • 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) – Oliver Schafeld Jul 03 '15 at 20:59
  • 2
    I had to also then run `pip install --upgrade pip` – thorr18 Jan 20 '16 at 04:48
  • Is pip depended on python version? I installed python3, but this command seems to be using python2. pip is installed successfully, though. – Felix Jun 19 '17 at 07:46
85

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

Basically, this consists in:

  • 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 macport) 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.

Florent Bruneau
  • 1,084
  • 9
  • 6
  • 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 Jun 26 '14 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. – Jorge Bucaran Feb 22 '15 at 08: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: http://stackoverflow.com/questions/34587473/what-is-get-pip-py-checksum-where-can-i-get-it-for-sure – Vladimir Ignatyev Jan 04 '16 at 13:06
  • 2
    It looks like the linked page has moved to https://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." – Taylor Edmiston Aug 09 '17 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. – Taylor Edmiston Aug 09 '17 at 19:14
44

For those who have both python2 & python3 installed, here's the solution:

python2.7 -m ensurepip --default-pip

Additionally, if you wanna install pip for python3.6:

wget https://bootstrap.pypa.io/get-pip.py
sudo python3.6 get-pip.py
Flimzy
  • 60,850
  • 13
  • 104
  • 147
Adam Liu
  • 1,071
  • 11
  • 15
42

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!

cbare
  • 10,730
  • 6
  • 47
  • 57
30

Download this file: get-pip.py

Then simply type

sudo python get-pip.py

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

For details, you can visit: http://pip.readthedocs.org/en/latest/installing.html

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

thegauraw
  • 4,462
  • 2
  • 18
  • 14
26

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

UPDATED - 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>.

Blaszard
  • 27,599
  • 40
  • 143
  • 217
  • 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 Dec 01 '17 at 19:59
  • @iamse7en Did you restart Terminal or open another tab? What is the log after the postinstall command? – Blaszard Dec 02 '17 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. – domdambrogia Dec 19 '17 at 03:34
  • I guess this will install python 3, and not pip. – Karthik RP Mar 08 '18 at 08:46
  • 5
    for those where it didn't work, look for pip3 but not "pip" and maybe create an alias – eMerzh Apr 20 '18 at 19:32
25

You should install 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

42wolf
  • 707
  • 7
  • 5
  • 8
    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... – GreenAsJade Nov 10 '13 at 03:10
19

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]

Emil Reña Enriquez
  • 2,572
  • 1
  • 26
  • 30
14
$ sudo port install py27-pip

Then update your PATH to include 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 new terminal window.

tpham
  • 185
  • 1
  • 3
12

To install or upgrade pip, download get-pip.py from http://www.pip-installer.org/en/latest/installing.html

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
...
goker.cebeci
  • 2,560
  • 19
  • 19
10

Install python3 first, then use pip3 to install packages.

brew install python

python3 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 python3.

FelixSFD
  • 5,456
  • 10
  • 40
  • 106
N.Lee
  • 824
  • 7
  • 13
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

MrE
  • 14,927
  • 10
  • 64
  • 89
8

Download python setup tools from the below website:

https://pypi.python.org/pypi/setuptools

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
thenakulchawla
  • 4,057
  • 5
  • 25
  • 37
  • 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 Apr 21 '20 at 09:02
4

Somehow easy install doesn't work on my old mac (10.8). This solve my problem.

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

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

-2

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.

user5359531
  • 2,546
  • 4
  • 19
  • 46
xu2mao
  • 492
  • 4
  • 8
  • 5
    Not related to the question – Don P Dec 06 '16 at 00:25
  • 3
    @DonnyP Actually, this suggestion [addresses the question](https://docs.continuum.io/anaconda/install) and would expeditiously solve the original problem as it comes with `pip`. This answer should be promoted and encouraged. – pylang Jan 18 '17 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. – Emil Reña Enriquez Aug 14 '17 at 03: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. – Anonymous Type Aug 03 '19 at 02: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. – user5359531 Jan 21 '20 at 18:46