How to install pip for Python 3 on Mac OS X?

288,125

Solution 1

UPDATE: This is no longer necessary with Python3.4. It installs pip3 as part of the stock install.

I ended up posting this same question on the python mailing list, and got the following answer:

# download and install setuptools
curl -O https://bootstrap.pypa.io/ez_setup.py
python3 ez_setup.py
# download and install pip
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py

Which solved my question perfectly. After adding the following for my own:

cd /usr/local/bin
ln -s ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pip pip

So that I could run pip directly, I was able to:

# use pip to install
pip install pyserial

or:

# Don't want it?
pip uninstall pyserial

Solution 2

I had to go through this process myself and chose a different way that I think is better in the long run.

I installed homebrew

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

then:

brew doctor

The last step gives you some warnings and errors that you have to resolve. One of those will be to download and install the Mac OS X command-line tools.

then:

brew install python3

This gave me python3 and pip3 in my path.

pieter$ which pip3 python3
/usr/local/bin/pip3
/usr/local/bin/python3

Solution 3

Install Python3 on mac

1. brew install python3
2. curl https://bootstrap.pypa.io/get-pip.py | python3
3. python3

Use pip3 to install modules

1. pip3 install ipython
2. python3 -m IPython

:)

Solution 4

Here is my simple solution:

If you have python2 and python3 both installed in your system, the pip upgrade will point to python2 by default. Hence, we must specify the version of python(python3) and use the below command:

python3 -m pip install --upgrade pip

This command will uninstall the previously installed pip and install the new version- upgrading your pip.

This will save memory and declutter your system.

Image - How the upgrading of pip in Python3 works on MacOS

Solution 5

Plus: when you install requests with python3, the command is:

pip3 install requests

not

pip install requests
Share:
288,125
Travis Griggs
Author by

Travis Griggs

Updated on January 11, 2022

Comments

  • Travis Griggs
    Travis Griggs over 2 years

    OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I can do it the way I've done it before, which is:

    1. Download pyserial from pypi
    2. untar pyserial.tgz
    3. cd pyserial
    4. python3 setup.py install

    But I'd like to do like the cool kids do, and just do something like pip3 install pyserial. But it's not clear how I get to that point. And just that point. Not interested (unless I have to be) in virtualenv yet.

  • Travis Griggs
    Travis Griggs over 10 years
    How does easy_install determine that it's for python3? I have a \usr\local\bin\easy_install dated Sep 13 2012. I'm suspicious that is from/for the stock 2.7. Sadly, easy_install --version isn't helpful. --help doesn't even give any useful hints.
  • l'L'l
    l'L'l over 10 years
    @TravisGriggs - do you also have 2.7 installed? i was assuming you were only using 3.3.x.
  • Travis Griggs
    Travis Griggs over 10 years
    I have not uninstalled the stock 2.7 version that is part of OSX. That would seem like a Bad Idea(tm).
  • l'L'l
    l'L'l over 10 years
    @TravisGriggs, well uninstalling 2.7 can be a bad idea if not done correctly. try typing which easy_install in terminal following by less <path/to/>easy_install. It should give me more information on the version you're using.
  • Travis Griggs
    Travis Griggs over 10 years
    Yeah, I had checked that. It's a binary, not a symlink. Since python3 mostly installs in /Library/Frameworks/Python/..., that makes me strongly suspicious that it is for 2.7.
  • l'L'l
    l'L'l over 10 years
    If your pythonpath is set to use 3.3.x then easy_installing pip should associate it with the latest version — or at least that's how mine works.
  • jfs
    jfs over 10 years
    to avoid confusion with pip that installs for Python 2.7, you could create the symlink named pip3 instead of ambiguous pip
  • nonex
    nonex over 9 years
    Thanks for this, was looking for a good solution. For people seeing this in the future (who will get the same message I got from ruby), the Homebrew installer has moved and the new command is: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/in‌​stall)"
  • radtek
    radtek over 8 years
    I didn't have to create a symlink, one was created automatically named pip3
  • Madhulika Mukherjee
    Madhulika Mukherjee over 8 years
    Following your answer step by step solved my problem. Thanks!
  • Taylor D. Edmiston
    Taylor D. Edmiston about 8 years
    Just to clarify for others, the script downloaded is from the official host for pip - pypi.python.org/pypi/pip
  • Gardner Bickford
    Gardner Bickford about 8 years
    Please add https to this example
  • Alan Dong
    Alan Dong about 8 years
    @GardnerBickford Added https
  • bubakazouba
    bubakazouba almost 8 years
  • shazeline
    shazeline almost 8 years
    bootstrap.pypa.io/ez_setup.py and bootstrap.pypa.io/get-pip.py are the updated links, though pip3 comes installed with python3 as OP mentioned.
  • tash
    tash over 7 years
    Thank you for that update! I've been searching for so long on how to install pip, only to find that it was already on my system! Just had to use "pip3". Cheers!
  • flik
    flik over 5 years
    $ which pip3 python3 /usr/local/bin/python3 getting result but when I try pip3 --version then error: pip3: command not found
  • Devran Cosmo Uenal
    Devran Cosmo Uenal almost 5 years
    Thanks! This is exactly what I was looking for — running macOS Catalina.
  • Ashish Rawat
    Ashish Rawat about 4 years
    Thanks a lot, saved quite some efforts.
  • Polluks
    Polluks over 3 years
    Latest command /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/in‌​stall.sh)"
  • kamp
    kamp over 2 years
    This is by far straight to the point solution!