8

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.

5
  • 1
    Did you check if there is now a pip2? Commented Apr 15, 2018 at 9:46
  • There is no pip2. 'The program 'pip2' is currently not installed. You can install it by typing: sudo apt install python-pip.' Commented Apr 15, 2018 at 9:48
  • Potentially you can create that link yourself: sudo ln -s /home/username/.local/lib/python2.7/site-packages/pip /usr/local/bin/pip2. Commented Apr 15, 2018 at 9:51
  • Both your pip and pip3 points to the same binary. You need to find pip (v2.7) exists and fix it using $PATH Commented Apr 15, 2018 at 9:53
  • Possible duplicate of python3.6-venv hijacks pip. what is a way to prevent this? Commented Apr 15, 2018 at 14:33

4 Answers 4

7

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
Sign up to request clarification or add additional context in comments.

1 Comment

didn't work for me
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)

Comments

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.

Comments

-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

1 Comment

py doesn't work in an OS that has /usr/bin/python (Ubuntu).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.