How to install pip with Python 3?
Asked Answered
B

23

696

I want to install pip. It should support Python 3, but it requires setuptools, which is available only for Python 2.

How can I install pip with Python 3?

Bestrew answered 5/7, 2011 at 18:58 Comment(3)
related: easy way to install distribute/pip/virtualenv. It supports Python 3 too.Fredfreda
@deamon: you may want to reconsider the accepted answer as distribute is deprecated and another answer solves the problem.Rideout
Imho this is best than the accepted answer : stackoverflow.com/questions/17443354/…Schoolhouse
W
865

edit: Manual installation and use of setuptools is not the standard process anymore.

If you're running Python 2.7.9+ or Python 3.4+

Congrats, you should already have pip installed. If you do not, read onward.

If you're running a Unix-like System

You can usually install the package for pip through your package manager if your version of Python is older than 2.7.9 or 3.4, or if your system did not include it for whatever reason.

Instructions for some of the more common distros follow.

Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 2.x

Run the following command from a terminal:

sudo apt-get install python-pip 

Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 3.x

Run the following command from a terminal:

sudo apt-get install python3-pip
Note:

On a fresh Debian/Ubuntu install, the package may not be found until you do:

sudo apt-get update

Installing pip on CentOS 7 for Python 2.x

On CentOS 7, you have to install setup tools first, and then use that to install pip, as there is no direct package for it.

sudo yum install python-setuptools
sudo easy_install pip

Installing pip on CentOS 7 for Python 3.x

Assuming you installed Python 3.4 from EPEL, you can install Python 3's setup tools and use it to install pip.

# First command requires you to have enabled EPEL for CentOS7
sudo yum install python34-setuptools
sudo easy_install pip

If your Unix/Linux distro doesn't have it in package repos

Install using the manual way detailed below.

The manual way

If you want to do it the manual way, the now-recommended method is to install using the get-pip.py script from pip's installation instructions.

Install pip

To install pip, securely download get-pip.py

Then run the following (which may require administrator access):

python get-pip.py 

If setuptools is not already installed, get-pip.py will install setuptools for you.

Weepy answered 5/7, 2011 at 19:1 Comment(21)
It's worth noting that the distribute install script has a --user flag that will install distribute just for the current user.Semiconductor
How does one use distribute to install pip? I can't seem to figure it out.Divertimento
@TylerCrompton - easy_install pip.Weepy
I ran "python3.3 distribute_setup.py". It seemed to work but the only easy_install on my PATH now are "easy_install" in Python2.7, plus "easy_install-2.6 easy_install-3.2 easy_install-2.5 easy_install-2.7" :-\Baumgartner
distribute has since been superseded by [setup_tools] (pypi.python.org/pypi/setuptools).Endosmosis
From pythonhosted.org/distribute: "Distribute is a deprecated fork of the Setuptools project.". It is abandoned and not being maintained anymore.Rideout
For some reason on my instance of Ubuntu 14.04 with python3.4 already installed from apt-get, I also had to run sudo easy_install3 pip and then pip3 install works from that point on.Specie
I installed pip the manual way , but now I have pip and pip3 both. If I run any of them with -V option, I get pip 8.0.2 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (python 3.5). How do I keep only one and remove the other?Minnieminnnie
pip is unfortunately not included with python 3.4 if you're on centos. See here for details: stackoverflow.com/questions/32618686/…Benyamin
@ak31 - pip is likely a symbolic link to pip3. If you do an ls -l $(which pip), it should probably show that.Weepy
@Benyamin - Python 3.4 isn't a default package on CentOS 7 - I've included some additional instructions for people running CentOS 7, assuming they use EPEL to install Python 3.4.Weepy
Pip's website says that it already comes with Python 3.4+ if you downloaded from python.org. However, when I type pip on terminal, I get command not found. So I decided to go through the python3's install docs again, where it mentions that python and pip should be accessed using the commands python3 and pip3 instead. This is not obvious from the documentation on either site.Alkaline
For those who want to use the manual install (get-pip.py), this won't work with python3.0 to 3.2...Jos
where is windows? I don't say that I'm using only windows, I have no problem to install all of this in ubuntu, by author didn't mention linux, why there such a discrimination, like python, pip doesn't exist for windows...Outset
This will install pip for python not for python3, the right way is sudo apt-get install python3-pipDisembodied
@Disembodied That's what it says in the Answer up there. M Installing it now... :|Muimuir
I did have to follow @jamescampbell tip to get it to work fully though.Muimuir
Collecting pip Using cached pip-9.0.1-py2.py3-none-any.whl Installing collected packages: pip Successfully installed pip-8.1.1 You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. This is bit strange...I'm fine with v8, I guess, but it always keeps saying the same message when I try to 'upgrade.' :|Muimuir
It is a bit confusing. I can report that the Debian command worked for Ubuntu 16 and Python3: sudo apt-get install python3-pip. pip was NOT installed with Python 3 for this Ubuntu's PPA. I used to use Python a lot -- There's really no need for a disregard for forward migration ... Yet it still happens. Some kind of interface management or poly-fill approach would save lots of trouble. Witness 17 x answers to the same question and more than a dozen comments on the accepted answer. Me thinks a smell.Virgenvirgie
The best way to avoid this kind of problem is using pyenv. I tried this solution without using pyenv it didn't solve the TLS problem.Svensen
Correct me if I am wrong but believe it's the same for Centos and amazon linux , sudo yum install python3-pipEyestrain
Q
233

I was able to install pip for python 3 on Ubuntu just by running sudo apt-get install python3-pip.

Quartan answered 25/11, 2012 at 19:22 Comment(9)
Then use pip-3.2 install (replace 3.2 with your version) to install the packages - also see stackoverflow.com/questions/10763440/…Hotchkiss
Unable to locate package python3-pip. Has it been renamed?Snoddy
Are you using Ubuntu 12.04 LTS? It's not available there.Eberly
+1 Confirmed working on ubuntu 13.04 after sudo apt-get install -y python3.3 and using type pip3Dehisce
I also just ran this on RPi and used it with sudo pip-3.2 install [packageName]Pasteurize
After you install python3-pip, if the package cannot be found, try python3 -m pipCareerist
seems to be just pip3 nowBurmese
Thabk you! @Hotchkiss and thanks for the link also. Lot of people saying virtualenv/..wrapper but these tools are installed via pip.. So for those who doesn't know (like me) if it's irrelevant the way you install pip we've got here an obvious question. I will use pip3 by now thank youExpiration
pip3 is works, but I had to use sudo pip3 install (for pandas at least)Bellybutton
R
89

Python 3.4+ and Python 2.7.9+

Good news! Python 3.4 (released March 2014) ships with Pip. This is the best feature of any Python release. It makes the community's wealth of libraries accessible to everyone. Newbies are no longer excluded by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Nodejs, Haskell, Perl, Go--almost every other contemporary language with a majority open-source community. Thank you Python.

Of course, that doesn't mean Python packaging is problem solved. The experience remains frustrating. I discuss this at Does Python have a package/module management system?

Alas for everyone using an earlier Python. Manual instructions follow.

Python ≤ 2.7.8 and Python ≤ 3.3

Follow my detailed instructions at https://mcmap.net/q/12627/-how-do-i-install-pip-on-windows . Essentially

Official instructions

Per https://pip.pypa.io/en/stable/installing.html

Download get-pip.py, being careful to save it as a .py file rather than .txt. Then, run it from the command prompt.

python get-pip.py

You possibly need an administrator command prompt to do this. Follow http://technet.microsoft.com/en-us/library/cc947813(v=ws.10).aspx

For me, this installed Pip at C:\Python27\Scripts\pip.exe. Find pip.exe on your computer, then add its folder (eg. C:\Python27\Scripts) to your path (Start / Edit environment variables). Now you should be able to run pip from the command line. Try installing a package:

pip install httpie

There you go (hopefully)!

Radu answered 4/3, 2013 at 21:36 Comment(8)
After python get-pip.py, I also make a symlink from pip3 in /Library/Frameworks/Python.framework/Versions/3.3/bin (for example) to my system PATH, to make pip3 available on command line.Elevation
By default, the commands pipX and pipX.Y will be installed on all platforms (where X.Y stands for the version of the Python installation), along with the pip Python package and its dependencies.Issiah
I just installed python 3.4.1 from scratch on windows 8. Where is pip? How can i start it?Cate
Ubuntu 14.04, just did apt-get install python3-dev, python 3.4 installed, no pip :(Immigration
I can install pip3.4 with Python 3.4 on CentOS 6.5. But I used the same method and failed to install pip3.4 on CentOS 7. Python3.4 is OK though.Hoem
@Cate it'll be in your Python installation. Add the Python bin folder to your path.Peewee
The version I just installed (Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32) does not have pip anywhere.Rideout
This is not true: "And, alas for everyone using an earlier Python. There's no plan to ship Pip to you." pip is shipped with 2.7.9+ as well as 3.4.0+. Of course that doesn't help people on 2.6 or 3.2, but the majority of people who need to use an earlier Python than 3.4 need to use 2.7.Pint
T
65

if you're using python 3.4+

just type:

python3 -m pip
Tephra answered 3/8, 2016 at 10:51 Comment(3)
On CentOS:6 docker image: python3 -m pip /usr/bin/python3: No module named pipPuzzle
that did the trick for me, for portalocker: python3 -m pip install portalockerCollator
Don't forget to use "python3" anywhere you see a command solution that uses "python ..." if your alias is set up to use python3 instead of python. Didn't click for me for a good couple hoursRigamarole
B
53

For Ubuntu 12.04 or older,

sudo apt-get install python3-pip

won't work. Instead, use:

sudo apt-get install python3-setuptools ca-certificates
sudo easy_install3 pip
Baez answered 4/2, 2014 at 9:42 Comment(0)
C
45

Update 2015-01-20:

As per https://pip.pypa.io/en/latest/installing.html the current way is:

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

I think that should work for any version


Original Answer:

wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
Chappell answered 8/7, 2013 at 0:17 Comment(2)
I think I've read about easy_install being depreciated due to insecure connections. I'd read up before using easy_install.Nonalcoholic
wget bootstrap.pypa.io/get-pip.py && python get-pip.py This works for me and upgrades pip3Matroclinous
A
36

Single Python in system

To install packages in Python always follow these steps:

  1. If the package is for python 2.x: sudo python -m pip install [package]
  2. If the package is for python 3.x: sudo python3 -m pip install [package]

Note: This is assuming no alias is set for python

Through this method, there will be no confusion regarding which python version is receiving the package.

Multiple Pythons/Virtual Envs

Say you have python3 ↔ python3.6 and python3.7 ↔ python3.7

  1. To install for python3.6: sudo python3 -m pip install [package]
  2. To instal for python3.7: sudo python3.7 -m pip install [package]

This is essentially the same method as shown previously.

Note 1

How to find which python? Do one of the following:

~ » python3 -c "import sys; print(sys.version)"
3.9.5 (default, Nov 18 2021, 16:00:48)

your python3 command spawns:

~ » python3
Python 3.9.5 (default, Nov 18 2021, 16:00:48) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Notice python 3.9.5 in the second line.

or say you are using virtual env and see where your python points to:

» which python
/home/ganesh/os/np-test/bin/python

Note 2

Change what python3 or python points to: https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3

Aubergine answered 7/11, 2016 at 13:9 Comment(3)
Of all these methods, this is the only way I managed to get pip to install for python3.5 when I have both 3.4 and 3.5 on the system.Louque
can't thank you enough. managing per version install/uninstall is a nightmare no longer.Paucker
No idea why this answer is upvoted. Question is regarding how to install pip and not how to install packages via pip. As a side-note, using sudo to install packages via pip is asking for dependency hell. Using pip you probably want to scope to your account or to a virtual environment.Catalinacatalo
A
33
python3 -m ensurepip

I'm not sure when exactly this was introduced, but it's installed pip3 for me when it didn't already exist.

Aspa answered 23/2, 2016 at 18:15 Comment(3)
Thank you, this command pointed my mistake: I built python 3.5 without libssl-dev package, so PIP was not builtEnforcement
This also worked on cygwin! First update: pip2 install --upgrade pip and apt-cyg install python3. Then what you wrote and you've got pip3.Tearful
This just works! Just tested on python3.11 sudo dnf install -y python311 update-alternatives --set python /usr/bin/python3.11 update-alternatives --set python3 /usr/bin/python3.11 python3 -m ensurepipSaida
H
17

Older version of Homebrew

If you are on macOS, use homebrew.

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

Also note that you should check the console if the install finished successfully. Sometimes it doesn't (e.g. an error due to ownership), but people simply overlook the log.


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

Howze answered 27/11, 2017 at 21:17 Comment(0)
N
14

This is the one-liner I copy-and-paste:

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

Alternate:

curl -L get-pip.io | python3

From Installing with get-pip.py:

To install pip, securely download get-pip.py by following this link: get-pip.py. Alternatively, use curl:

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

Then run the following command in the folder where you have downloaded get-pip.py:

python get-pip.py

Warning: Be cautious if you are using a Python install that is 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.

Northcutt answered 27/5, 2020 at 16:52 Comment(1)
This response shouldn't be so low down.Catalinacatalo
R
9

If your Linux distro came with Python already installed, you should be able to install PIP using your system’s package manager. This is preferable since system-installed versions of Python do not play nicely with the get-pip.py script used on Windows and Mac.

Advanced Package Tool (Python 2.x)

sudo apt-get install python-pip

Advanced Package Tool (Python 3.x)

sudo apt-get install python3-pip

pacman Package Manager (Python 2.x)

sudo pacman -S python2-pip

pacman Package Manager (Python 3.x)

sudo pacman -S python-pip

Yum Package Manager (Python 2.x)

sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel

Yum Package Manager (Python 3.x)

sudo yum install python3 python3-wheel

Dandified Yum (Python 2.x)

sudo dnf upgrade python-setuptools
sudo dnf install python-pip python-wheel

Dandified Yum (Python 3.x)

sudo dnf install python3 python3-wheel

Zypper Package Manager (Python 2.x)

sudo zypper install python-pip python-setuptools python-wheel

Zypper Package Manager (Python 3.x)

sudo zypper install python3-pip python3-setuptools python3-wheel
Ronaldronalda answered 11/8, 2018 at 11:31 Comment(0)
R
5

Please follow below steps to install python 3 with pip:

Step 1 : Install Python from download here

Step 2 : you’ll need to download get-pip.py

Step 3 : After download get-pip.py , open your commant prompt and go to directory where your get-pip.py file saved .

Step 4 : Enter command python get-pip.py in cmd.

Step 5 : Pip installed successfully , Verify pip installation by type command in cmd pip --version

Reiss answered 29/5, 2019 at 6:54 Comment(0)
N
4

If you use several different versions of python try using virtualenv http://www.virtualenv.org/en/latest/virtualenv.html#installation

With the advantage of pip for each local environment.

Then install a local environment in the current directory by:

virtualenv -p /usr/local/bin/python3.3 ENV --verbose

Note that you specify the path to a python binary you have installed on your system.

Then there are now an local pythonenvironment in that folder. ./ENV

Now there should be ./ENV/pip-3.3

use ./ENV/pip-3.3 freeze to list the local installed libraries.

use ./ENV/pip-3.3 install packagename to install at the local environment.

use ./ENV/python3.3 pythonfile.py to run your python script.

Nonobservance answered 2/12, 2013 at 10:40 Comment(0)
O
3

Here is my way to solve this problem at ubuntu 12.04:

sudo apt-get install build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev

Then install the python3 from source code:

wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz
tar xvf Python-3.4.0.tar.xz
cd Python-3.4.0
./configure
make
make test
sudo make install

When you finished installing all of them, pip3 will get installed automatically.

Operator answered 12/4, 2014 at 3:49 Comment(1)
ImportError: No module named 'pip' after I did all these for python3.4.1 from source off the original python website! Python 3.4.1 (default, Aug 4 2016, 16:56:02) [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwinBronchoscope
M
3

This is what I did on OS X Mavericks to get this to work.

Firstly, have brew installed

Install python 3.4

brew install python3

Then I get the latest version of distribute:

wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip#md5=c6c59594a7b180af57af8a0cc0cf5b4a

unzip distribute-0.7.3.zip
cd distribute-0.7.3
sudo setup.py install
sudo easy_install-3.4 pip
sudo pip3.4 install virtualenv
sudo pip3.4 install virtualenvwrapper

mkvirtualenv py3 

python --version
Python 3.4.1

I hope this helps.

Machzor answered 7/8, 2014 at 23:9 Comment(2)
This helped until the mkvirtualenv py3 line - on OS X El Capitan, i get a command not found error. Also, to actually use python 3 after using brew to install it, i have to run python3 rather than just python which still maps to python 2.7. are there different steps for El Capitan?Araarab
@Araarab you would run python3 or you could symlink it:Machzor
S
3

If you used the command "python get-pip.py", you should have the 'pip' function for Python3. However, 'pip' for Python2 might still be present. In my case I uninstalled 'pip', which removed it from Python2.

After that I ran "python get-pip.py" again. (Make sure that 'get-pip.py' is saved in the same folder as Python3.) The final step was to add the directory with 'pip' command to $PATH. That solved it for me.

Sorrells answered 18/7, 2022 at 6:23 Comment(0)
T
2

For python3 try this:

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python

The good thing is that It will also detect what version of python you have (even if it's an environment of python in your custom location). After this you can proceed normally with (for example)

pip install numpy

source: https://pypi.python.org/pypi/setuptools/1.1.6#upgrading-from-setuptools-0-6

Tallula answered 27/9, 2013 at 21:35 Comment(0)
I
2

What’s New In Python 3.4

...

pip should always be available

...

By default, the commands pipX and pipX.Y will be installed on all platforms (where X.Y stands for the version of the Python installation), along with the pip Python package and its dependencies.

https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-453

so if you have python 3.4 installed, you can just: sudo pip3 install xxx

Issiah answered 2/8, 2014 at 11:24 Comment(1)
pip3 was not installed when I installed Python 3.4, I had to follow instructions here to get it.Borkowski
L
2

Assuming you are in a highly restricted computer env (such as myself) without root access or ability to install packages...

I had never setup a fresh/standalone/raw/non-root instance of Python+virtualenv before this post. I had do quite a bit of Googling to make this work.

  1. Decide if you are using python (python2) or python3 and set your PATH correctly. (I am strictly a python3 user.) All commands below can substitute python3 for python if you are python2 user.
  2. wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-x.y.z.tar.gz
  3. tar -xzvf virtualenv-x.y.z.tar.gz
  4. python3 virtualenv-x.y.z/virtualenv.py --python $(which python3) /path/to/new/virtualenv
  5. source /path/to/new/virtualenv/bin/activate
    • Assumes you are using a Bourne-compatible shell, e.g., bash
    • Brilliantly, this virtualenv package includes a standalone version of pip and setuptools that are auto-magically installed into each new virtualenv. This solves the chicken and egg problem.
    • You may want to create an alias (or update your ~/.bashrc, etc.) for this final command to activate the python virtualenv during each login. It can be a pain to remember all these paths and commands.
  6. Check your version of python now: which python3 should give: /path/to/new/virtualenv/bin/python3
  7. Check pip is also available in the virtualenv via which pip... should give: /path/to/new/virtualenv/bin/pip

Then... pip, pip, pip!

Final tip to newbie Pythoneers: You don't think you need virtualenv when you start, but you will be happy to have it later. Helps with "what if" installation / upgrade scenarios for open source / shared packages.

Ref: https://virtualenv.pypa.io/en/latest/installation.html

Linalool answered 31/3, 2015 at 12:49 Comment(0)
C
2

To install pip, securely download get-pip.py.

Then run the following:

python get-pip.py

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.

Refer: PIP Installation

Cedar answered 27/11, 2016 at 19:3 Comment(0)
W
1

And for Windows 8.1/10 OS Users just open cmd (command prompt)

write this : C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36-32\Scripts

then

just write this : pip3 install {name of package}

Hint: the location of folder Python36-32 may get different for new python 3.x versions

Waac answered 10/7, 2018 at 9:22 Comment(2)
You can also do this in PowerShell of course. Also the '-32' refers to the 32bit version of Python. So for me the path was .\Python37\scripts\ as I was targeting the 64bit version of Python.Crinkle
This doesn't answer the question asked, which was about how to install pip, not how to install stuff with pip.Chapen
Q
1

pip is installed together when you install Python. You can use sudo pip install (module) or python3 -m pip install (module).

Quiles answered 8/1, 2019 at 5:36 Comment(0)
W
-2

=>Easy way to install Python any version on Ubuntu 18.04 or Ubuntu 20.04 follow these steps:-

Step 1: Update Local Repositories:-

sudo apt update

Step 2: Install Supporting Software:-

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

Step3: Create directory on your home directory To download the newest release of Python Source Code, navigate to the /python-source-files directory and use the wget command:-

mkdir python-source-files

Step 4: Download the Latest Version of Python Source Code:-

wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz

"you can change python version by just modifies this:-"3.7.5" with the version you want example:-"3.5.2"

Step 5: Extract Compressed Files:-

tar –xf Python-3.7.5.tgz or tar xvzf Python-3.7.5.tgz

Step 6: Test System and Optimize Python:-

cd python-3.7.5 or your version of python.

Step 7: Now configure(Using the ––optimization option speeds code execution by 10-20%.):-

./configure ––enable–optimizations

OR you can also do this also if you facing ssl error:-

./configure --with-openssl

Step 8: Install a Second Instance of Python:-

sudo make altinstall

"It is recommended that you use the altinstall method. Your Ubuntu system may have software packages dependent on Python 2.x.

OR

If you want to Overwrite Default Python Installation/version:-

sudo make install"

Step 9:Now check Python Version:-

python3 ––version

Step 10: To install pip for python3 just go with this command:-

sudo apt-get install python3-pip

Wherever answered 7/1, 2021 at 16:3 Comment(1)
"easy way of installing" and you recommend building the python source? way easier is to use the existing python installation and grab the get-pip.py file.Catalinacatalo

© 2022 - 2024 — McMap. All rights reserved.