Steven Mercatante Steven Mercatante - 2 months ago 7
Python Question

Stuck with old version of oauth2client when using Vagrant

I've got a script that uses

gcloud
v0.7.1. As soon as I run it, I get the following error:

...
File "/home/vagrant/venvs/lib/python2.7/site-packages/gcloud/credentials.py", line 26, in <module>
from oauth2client.client import _get_application_default_credential_from_file
ImportError: cannot import name _get_application_default_credential_from_file


As far as I can tell, an older version (v1.2) of
oauth2client
is being used, even though I did a
pip install oauth2client==1.5.0
. This only happens on my Vagrant box (running CentOS 6.6, Python v 2.7.10, pip v7.1.2). When I'm outside of the Vagrant box I don't get this error.

pip show oauth2client
(from within the Vagrant box) yields:

Metadata-Version: 2.0
Name: oauth2client
Version: 1.5.0
Summary: OAuth 2.0 client library
Home-page: http://github.com/google/oauth2client/
Author: Google Inc.
Author-email: UNKNOWN
License: Apache 2.0
Location: /home/vagrant/venvs/lib/python2.7/site-packages
Requires: six, pyasn1-modules, rsa, pyasn1, httplib2


However, I get back a different version number when I check it from Python using this command:

python -c "import oauth2client; print oauth2client.__version__; print oauth2client.__file__"
:

1.2
/home/vagrant/venvs/lib/python2.7/site-packages/oauth2client/__init__.pyc


import sys; print sys.path
yields:

['', '/home/vagrant/venvs/lib/python27.zip', '/home/vagrant/venvs/lib/python2.7', '/home/vagrant/venvs/lib/python2.7/plat-linux2', '/home/vagrant/venvs/lib/python2.7/lib-tk', '/home/vagrant/venvs/lib/python2.7/lib-old', '/home/vagrant/venvs/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/home/vagrant/venvs/lib/python2.7/site-packages']


How can I make sure that v1.5.0 is used?

Answer

I spent a bunch of time on a similar problem tonight, so hope this helps: the google-api-python-client library used to bundle the oauth2client library until it was split out in a separate package. If you have google-api-python-client<=1.2 installed, it may interfere with your installation of oauth2client, depending on the order in which you installed the libraries or your PYTHONPATH.

Python (with packages installed via pip) doesn't offer any guarantee that the folder you find in site/dist-packages is actually installed by the package of the same name.

Comments