Steven Mercatante Steven Mercatante - 11 months ago 43
Python Question

Stuck with old version of oauth2client when using Vagrant

I've got a script that uses

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

File "/home/vagrant/venvs/lib/python2.7/site-packages/gcloud/", 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
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
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__"


import sys; print sys.path

['', '/home/vagrant/venvs/lib/', '/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 Source

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.