'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.
Solution 1:[1]
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.
Solution 2:[2]
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
Solution 3:[3]
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
Solution 4:[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.
Solution 5:[5]
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
Solution 6:[6]
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
Solution 7:[7]
run this
python2.7 -m ensurepip --upgrade
Solution 8:[8]
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
1. sudo apt install python2-pip-whl
2. sudo apt install python2-setuptools-whl
3 virtualenv -p /usr/bin/python2.7 YOURPROJECT
4. 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Edward Gaere |
| Solution 2 | gawel |
| Solution 3 | Swish Tom |
| Solution 4 | Games Brainiac |
| Solution 5 | |
| Solution 6 | код е |
| Solution 7 | Akhil |
| Solution 8 | Sohail |
