Reputation: 140613
I started to experiment with shade today; and installed it for both python2 and python3 on my ubuntu 16.04 system; using:
sudo pip install shade
respectively
sudo pip3 install shade
Both commands passed; I didn't really pay attention.
Then I tried to run this little test script:
from shade import *
simple_logging(debug=True)
conn = openstack_cloud(cloud='myopenstack')
images = conn.list_images()
for image in images:
print(image)
Using python3, I got a certificate error (which is fine, I would be rather surprised to find our internal infrastructure to use correct certificates).
But just to be sure, I wanted to run with python2.7, too; and I am told:
ImportError: No module named shade
So, I had a closer look what pip and pip3 have to say:
> pip -V
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
> pip3 -V
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
It looks like both pip
and pip3
are actually working on my python3 installation, but when I do:
> python --version
Python 2.7.12
> python3 --version
Python 3.5.2
Any idea, anybody? What could be causing this, or how to actually install shade for python2/pip?
As requested:
> for i in pip pip3 python python3 ; do type $i ; done
pip is /usr/local/bin/pip
pip3 is /usr/local/bin/pip3
python is /usr/bin/python
python3 is /usr/bin/python3
Upvotes: 7
Views: 9902
Reputation: 554
I ran into this problem (where pip got associated with Python 3) and it's due to the pip installer updating pip to point to Python 3. I think this is very confusing behavior because historically everyone has associated pip with Python 2 and pip3 with Python 3. We got around this by doing the following:
# install pip
curl https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py
sudo python3 /tmp/get-pip.py
sudo python /tmp/get-pip.py # install the python2 version last so the pip binary is not overwritten with the python3 version
rm /tmp/get-pip.py
The key here is installing the Python 2 pip after installing the Python 3 pip.
Upvotes: 1
Reputation: 321
Just change the first line of the /usr/local/bin/pip
to:
#!/usr/bin/python
and the first line of /usr/local/bin/pip3
to:
#!/usr/bin/python3
And then it will act normally:
> pip -V
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
> pip3 -V
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
Upvotes: 8
Reputation: 34744
pip3
looks like the default option pip
uses. Try using pip2
instead to explicitly install a Python 2 package.
Upvotes: 8
Reputation: 168836
Your local install of python3's pip in /usr/local/bin/ shadows the system install of pip in /usr/bin. In order to use the system's default pip, you can:
sudo /usr/bin/pip install shade
pip
: sudo rm /usr/local/bin/pip
/usr/bin
to /usr/local/bin
pip2
alias from /usr/bin
: sudo pip2 install shade
python3
from the system repositories: sudo apt-get install python3
. Don't forget to delete your local python3
install if you go this route.Upvotes: 1
Reputation: 177825
python -m pip
This will use the version of pip that python can see.
Upvotes: 5