Ubuntu 16: pip install installs to python 3 instead of 2

I upgraded to Ubuntu 16.04. I know it came with only python 3 installed, but somehow python 2 got in there ( I guess as a dependency). That's ok because i would add it anyway. Both python versions are present as can be seen with:

$ python --version
Python 2.7.11+
$ python3 --version
Python 3.5.1+

My problem is that pip and pip3 both default to python3 (and there's no pip2 either). For example:

$ sudo -H pip install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/local/lib/python3.5/dist-packages
$ sudo -H pip3 install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/local/lib/python3.5/dist-packages

For what it's worth they are referring to different fodlers:

$ which pip
/usr/local/bin/pip
$ which pip3
/usr/local/bin/pip3

How do I make pip install to python2 and pip3 install to python3 like in Ubuntu 14.04?


Solution 1:

after installing both

sudo apt-get install python-pip
sudo apt-get install python3-pip

under Ubuntu 16.04 I can simply use

pip2 install module
pip3 install module

to install the desired module for Python2 or Python3, respectively.

I hope that is helpful and works for you, too!

Solution 2:

Face same issue solved by unlinking pip from python3 by reinstalling it as following:

sudo python -m pip install -U --force-reinstall pip