Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install pip for Python 2

I run

python --version

and get

Python 2.7.3

I run

pip --version

and get

pip 1.5 from /usr/local/lib/python3.2/dist-packages/pip-1.5-py3.2.egg (python 3.2)

I installed pip using apt-get. How to I get the Python 2 version of pip?

I've reinstalled python and python-pip several times with apt-get. I'm also curious why these would install different Python versions.

like image 785
Paul Draper Avatar asked Jan 23 '14 10:01

Paul Draper


People also ask

Does pip work Python 2 and 3?

Install pip3 Ubuntu and Debian LinuxUbuntu 18.04 has both Python 2 and Python 3 installed by default, and hence has two pip variants for each Python version. 'pip', refers to Python 2. pip3 refers to Python 3. Ubuntu 20.4 has only Python 3, but still requires a separate python-pip 3 installation.


4 Answers

To install pip for Python2 on Ubuntu, this worked for me

sudo apt update curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py sudo python2 get-pip.py 

It's based on DareDevil7's answer but notice the url is different.

like image 126
Edward Gaere Avatar answered Sep 23 '22 02:09

Edward Gaere


I would suggest that you use pyenv to manage multiple versions of Python, because it can often get problematic. Right now the solution to the problem would depend on the configuration you have for pip and python in your bash.

One thing you can do is download the easy_install script, and use python 3 to run it and install pip for python 3 alone.

like image 24
Games Brainiac Avatar answered Sep 22 '22 02:09

Games Brainiac


If there are both python2.7 and python3 in you ubuntu system,run this

sudo apt install python-pip

There will be pip for python3 ,pip2 for python2

like image 43
Swish Tom Avatar answered Sep 20 '22 02:09

Swish Tom


If you really want to install pip globally for your system use the get-pip.py script with the wanted python binary http://www.pip-installer.org/en/latest/installing.html#install-or-upgrade-pip

python2.7 get-pip.py

But you should consider using virtualenv / buildout to get an isolated environment

like image 26
gawel Avatar answered Sep 20 '22 02:09

gawel