Can't install pip on python 2.7, only python 3

2019-08-29 13:27发布

问题:

I have been trying to install pip for python 2.7, but I am unable to. I want pip to work for both python 2.7 and python 3. Here is a summary of what I have done so far:

python -V
Python 2.7.15

echo $PATH
... /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin ...

I've also done a few checks to know where everything is (I have two '/usr/local/bin/python'). I believe there should only be one?

which -a python
/usr/local/bin/python
/usr/local/bin/python
/usr/bin/python

which python
/usr/local/bin/python

ls -l $(which python)
lrwxr-xr-x  1 XXXXX  admin  36 May 24 14:28 /usr/local/bin/python -> ../Cellar/python@2/2.7.15/bin/python

When I do:

brew list python | grep pip

I only get results for python3, nothing at all for python2

/usr/local/Cellar/python/3.6.5/bin/pip3

Things I have tried that do not work, include:

python get-pip.py
"can't open file 'get-pip.py': [Errno 2] No such file or directory"

brew install pip
"Error: No available formula with the name "pip" "

I appreciate your help!

回答1:

To download get_pip.py file run

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then try

python get-pip.py

Docs here: https://pip.pypa.io/en/stable/installing/



回答2:

It seems you are on a Mac. Since you have Python installed, that means you have easy_install as well.

sudo easy_install pip


回答3:

I'm using linux Ubuntu and could solve my Pip/Python environment following this steps:

Restore PYTHON 3:

sudo apt update
sudo apt install python3-pip
pip3 --version

if necessary...

sudo python3 -m pip install -U --force-reinstall pip

Restore PYTHON 2:

sudo apt update
sudo apt install python-pip
pip --version

if necessary...

sudo python -m pip install -U --force-reinstall pip==9.0.3

In my case the last command was the one that make the big trick I was missing. Moreover the version 9.0.3 is the last version works for me.