119

I am trying to install the Pillow module for python 3.3, but for that I need to install pip. Every time that I install pip it installs for python 2.7, any help?

1
  • 2
    it should be easy with sudo apt-get install python3-pip, however I get it can't find it. Did you have that problem too? Did you fix it? Dec 16, 2016 at 3:26

10 Answers 10

143

2018 Update: This is still attracting upvotes which worries me.

12.04 has been unsupported for about a year now. The best way you can install pip3 is by upgrading to a newer, supported version of Ubuntu. You have 3 LTS versions to pick from.


While on more modern versions of Ubuntu you could just sudo apt-get install python3-pip (and then use pip3), a Python 3 copy of pip was never packaged for 12.04.

Therefore you need to follow the more old fashioned install route with easy_install:

sudo apt-get install python3-setuptools
sudo easy_install3 pip

Now, there is every chance that this will clash with Python 2's pip and override /usr/bin/pip, because it will install a python3 based /usr/local/bin/pip which is also in Ubuntu 12.04's $PATH.

It shouldn't overwrite it so as long as you know that, it might be acceptable. However it might be best to start investigating the happy world of virtualenv as this answer suggests.

Alternatively you could rename the easy-installed python3 version of pip:

sudo mv /usr/local/bin/pip /usr/local/bin/pip-3

Then you can confirm your existing pip is still python2.7 based:

pip --version
10
  • 1
    This causes problems for some people, with non-world-readable files in /usr/local/lib/python3.2/dist-packages/. Nov 21, 2014 at 11:01
  • 1
    This is undoubtedly the best answer to the stated question, but if one is using a newer version of Ubuntu, dmeu answer below is more appropriate.
    – brandizzi
    Dec 2, 2015 at 18:57
  • 1
    Don't do this. This hoses your install. pip8 wants python3.4 but this will put on python3.2 as a requirement for python3 setup tools and then you can't uninstall it when pip3 fails to run because of compatibility issues. It completely breaks everything. Here's notes to get you back to a stable place getpostdelete.com/unscrewing.txt (this is for LTR 12.04). Note that this won't run as a script. Read each comment and decide for yourself if you want to incur the involved risks. Been linuxing for 20 years but I make no claim that this solution is right for you. Feb 28, 2016 at 1:02
  • 1
    sudo apt-get install python3-setuptools and sudo easy_install3 pip works fine on Ubuntu Trusty (14.04) ;-) Aug 28, 2017 at 22:09
  • 1
    you git an upvote for the 12.04 being outdated from me ;)
    – Markus
    Jul 25, 2018 at 15:53
43

You may also install it by sudo apt-get install python3-pip and then call it by pip3. Et voilà

7
  • 15
    Not on Ubuntu 12.04 LTS. Nov 21, 2014 at 11:01
  • 2
    @MariusGedminas Then maybe you shouldn't be exclusively using an outdated repository. Even if precise is still supported, that doesn't necessarily mean it has the latest software. It just means that they're keeping it online, on the "official repo", rather than moving it to the "old repo" where apt-get won't be able to access it; so that your package manager doesn't break. Case in point: I tried it, and it works fine; my sources.list uses the trusty repo, which can be used in 12.04 by just making a few additions to your sources.list and performing an apt-get update. Jan 29, 2015 at 16:45
  • 1
    Also note the anaconda possibility
    – dmeu
    May 4, 2016 at 16:54
  • this is useful when you want to install pip3 globally May 12, 2016 at 23:35
  • @BradenBest not sure if this is true but it seems its the version of ubuntu in docker. What version should I be using? I am also having issues installing pip3 and wish to install it. Dec 16, 2016 at 3:19
13

If you work with several versions of python on the same machine, it might be useful to work with virtual environments. This allows you to work with as many instances of python you want, each with their own set of packages. This is very useful if you're working with several versions of python, and/or if your projects require different versions of the same package(s).

To set this up:

sudo pip install virtualenv 

This can be done with ANY pip, so also with the standard pip using python 2.7. Then, to make a virtual environment with python3 as the interpreter, do:

virtualenv my_py3 --python=/usr/bin/python3
source my_py3/bin/activate # to activate the python3 environemt

Then install any packages you might want using

pip install <package> # no sudo required now, as you're IN the virtual environment

To stop the virtual environment, simple type:

deactivate
2

After installing python 3.3 using a PPA for Ubuntu 12.04, I installed easy_install 3.3 using locally using the following commands

wget http://python-distribute.org/distribute_setup.py
python3.3 -m distribute_setup install --user
easy_install-3.3 --user pip

This avoids polluting the site's installation of pip and easy_install. Finally, I added $HOME/.local/bin to my path. Now I can run pip3.3!

2

To add to dmeu's answer, you may have to update your /etc/apt/sources.list to include mirrors from a more recent repository, such as trusty.

sudo vi /etc/apt/sources.list
sudo apt-get update

To clarify on what Long-term support means, it does not necessarily mean that they are keeping precise up-to-date with the latest and greatest software. Sure, you will get a few updates from it, but then you'll have cases where certain packages don't exist, like python3-pip, which does exist in the trusty repo, for example.

What LTS means, is that they are keeping precise on the main repo, so that your package manager doesn't break. This will ultimately give you a chance perform an apt-get update, upgrade, and dist-upgrade when 12.04 finally becomes obsolete. They call it support, rather than cutting-edge, for a reason.

If the apt-get route still doesn't work, you may also try downloading a .deb package of python3-pip, and using dpkg, a.k.a. the debian package manager, to install it

sudo dpkg -i <name-of-package>.deb

Hope this helps.

2
  • 2
    On a fresh Ubuntu 18.04 LTS, sudo apt-get install python3-pip could not find python3.pip. Executing sudo apt-get update then repeating the failed install worked. Oct 17, 2018 at 17:48
  • @DavidChing just in case there's any confusion, Trusty is 14.04. Oct 18, 2018 at 4:34
1

by now my favorite option is to install anaconda or miniconda for python3: https://www.continuum.io/downloads

Any package can be installed by conda install package-name

If you need python2, you can create a virtual environment:

conda create -n python2 python=2.7 anaconda source activate python2

See details here: https://stackoverflow.com/a/24415581/551694

1

I tried following commands:

sudo apt-get update
sudo apt-get install python3-pip

This seemed to do the trick for me. I hope this helps others having the same issue.

1

Adding universe to the repositories does the trick.
Here I found it:

Blockquote You have to enable universe category which contains python-pip package.

Open /etc/apt/sources.list using an editor

sudo nano /etc/apt/sources.list

then add universe at the end of each line, like this:

deb http://archive.ubuntu.com/ubuntu bionic main universe
deb http://archive.ubuntu.com/ubuntu bionic-security main universe 
deb http://archive.ubuntu.com/ubuntu bionic-updates main universe

then run:

sudo apt update

and finally:

sudo apt install python-pip
0

It is not available in older package manager versions. Upgrade your package manager version using sudo apt update && sudo apt upgrade -y and it works perfectly fine.

0

As of 2022/08 the main issues are

  • PyPi has dropped support for http, so you need to use switch: -i https://pypi.python.org/simple/
  • PyPi requires SNI support for https. You can find this out by checking out the error messages ~/.pip/pip.log
  • Pip requires minimum Python 3.5, so valid upgrade alternatives are i) (as suggested by @allanlaal) use bionic packages ii) compile python from source or iii) use the following packages from legacy ppa deadsnakes + easy_install

The installation procedure:

echo |add-apt-repository ppa:fkrull/deadsnakes
apt-get update
apt-get -y install python3.5 python3-setuptools
rm /usr/bin/python3
ln -sf /usr/bin/python3.5 /usr/bin/python3
cd /opt
git clone https://github.com/pypa/setuptools.git
cd setuptools
git reset --hard 7ff173926c4773d39f3320ff0c9d65afb290e7b1 #50.3.2 - last version that supports python 3.5
python3 bootstrap.py
python3 setup.py install
easy_install3 -i https://pypi.python.org/simple/ pip==20.3.4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .