6

I am using python2.7 and python3.5 on Ubuntu 16.04. After upgrading pip to v10 I am no longer able to install packages for python2.7 using pip.

How can I change pip to point to python2.7?

$ pip -V
pip 10.0.0 from /home/username/.local/lib/python3.5/site-packages/pip (python 3.5)

$ pip3 -V
pip 10.0.0 from /home/username/.local/lib/python3.5/site-packages/pip (python 3.5)

$ which python
/usr/bin/python

$ which python3
/usr/bin/python3

$ python -V
Python 2.7.12

$ python3 -V
Python 3.5.2

$ which pip
/usr/local/bin/pip

$ which pip3
/usr/local/bin/pip3

$ python3 -m pip install some_module
$ python -m pip install some_module

python/python3 -m pip install some_module both installs to python 3.5.

Using Anaconda is not an option.

Blaszard
  • 30,954
  • 51
  • 153
  • 233
user6453877
  • 314
  • 1
  • 4
  • 14
  • 1
    Did you check if there is now a `pip2`? – Tom de Geus Apr 15 '18 at 09:46
  • There is no pip2. 'The program 'pip2' is currently not installed. You can install it by typing: sudo apt install python-pip.' – user6453877 Apr 15 '18 at 09:48
  • Potentially you can create that link yourself: `sudo ln -s /home/username/.local/lib/python2.7/site-packages/pip /usr/local/bin/pip2`. – Tom de Geus Apr 15 '18 at 09:51
  • Both your `pip` and `pip3` points to the same binary. You need to find `pip` (v2.7) exists and fix it using $PATH – Chen A. Apr 15 '18 at 09:53
  • Possible duplicate of [python3.6-venv hijacks pip. what is a way to prevent this?](https://stackoverflow.com/questions/45871761/python3-6-venv-hijacks-pip-what-is-a-way-to-prevent-this) – phd Apr 15 '18 at 14:33

4 Answers4

5

Had a very similar problem. Forced re-installation of pip caused pip to point back to python 2.7

sudo python -m pip install -U --force-reinstall pip
sotmot
  • 1,256
  • 2
  • 9
  • 21
1

On my system, I have a pip2 which points to the python you're looking for. For clarity, I just stopped using pip and only ever use pip2 or pip3. Not sure if this was a thing back when this question was asked, but looks to be the general solution now.

pip3 -V

pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

pip2 -V

pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

TheGrimmScientist
  • 2,812
  • 1
  • 27
  • 25
0

The problem is that pip is not pointing to the correct python version. I tried installing python-pip package:

sudo apt-get install python-pip

Then, pip2 and pip2.7 came out available in my terminal again:

$pip [press tab tab]
pip     pip2    pip2.7  pip3    pip3.5  

Now I upgraded pip2 with:

$pip2 install --upgrade pip
$pip2 -V
pip 20.0.2 from /home/diego/.local/lib/python2.7/site-packages/pip (python 2.7)

Currently with version 20.0.2 of pip2, that is now pointing to python2.7, it's available to install any package into the specific version we need.

-1

In my case python points to 2.7 while py works to 3.6. You can check this by typing py in Terminal, and if so then

py -m pip install something
Blaszard
  • 30,954
  • 51
  • 153
  • 233
Cristian
  • 17
  • 1