user6453877
user6453877

Reputation: 334

Changing which Python version pip points to

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.

Upvotes: 8

Views: 23432

Answers (4)

DarmVillegas
DarmVillegas

Reputation: 1

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.

Upvotes: 0

sotmot
sotmot

Reputation: 1313

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

Upvotes: 7

TheGrimmScientist
TheGrimmScientist

Reputation: 2897

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)

Upvotes: 1

Cristian
Cristian

Reputation: 17

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

Upvotes: -1

Related Questions