53

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.

Paul Draper
  • 78,542
  • 46
  • 206
  • 285
  • [This](http://stackoverflow.com/questions/10960805/apt-get-install-for-different-python-versions) question is similar or duplicate for this when you try to install using apt-get –  Jan 23 '14 at 15:12

8 Answers8

79

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.

Edward Gaere
  • 1,092
  • 6
  • 11
6

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

Swish Tom
  • 125
  • 1
  • 2
4

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.

Games Brainiac
  • 80,178
  • 33
  • 141
  • 199
4

run this

python2.7 -m ensurepip --upgrade
Akhil
  • 912
  • 12
  • 23
  • 1
    Very useful. Needed pip to install virtualenv for supporting legacy code on AWS Linux. Also appreciated (a) no need for internet access (b) support of --user option to keep things isolated. https://docs.python.org/2.7/library/ensurepip.html#module-ensurepip – Jonathan Bliss Mar 08 '23 at 06:30
3

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

gawel
  • 2,038
  • 14
  • 16
2

Download the tar.gz of pip from https://pypi.python.org/pypi/pip#downloads.

Unzip or Untar, Then from its untar directory install for any specific version of python using

python2.7 setup.py install

or

python3.3 setup.py install
1

Run the following Commands:

sudo add-apt-repository universe
sudo apt update
curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
sudo python get-pip.py
код е
  • 196
  • 2
  • 11
0

Its a not a good idea to install pip for python2 system wide. I guess, you need to run a project with python2. The best solution is vritualenv. I am making an assumption that in your installation which python2 returns /usr/bin/python2.7 and virtualenv --version returns virtualenv 20.15.1 from home/user/.local/lib/python2.7/site-packages/virtualenv/__init__.pyc

   1  virtualenv -p /usr/bin/python2.7 YOURPROJECT
   2. source YOURPROJECT/bin/activate

The last command will now activate the virtual environment and in this environment, your python is python2.7 and pip is installed for python2.7 as well. You can deactivate your virtual environment using deactivate.

Sohail
  • 309
  • 5
  • 13