The following problem has been encountered by me and others in a variety of different GCP projects, and under circumstances where the same code worked a few days earlier.
I am walking through all of the steps again right now, just to make sure that I still see the same thing. I started by deleting the running instance of Cloud Datalab in my GCP project, and then I started over: first deploy Datalab, then "start using" Datalab.
I then select a pre-existing notebook that I have which starts with the following lines:
!pip install --upgrade google-api-python-client
from httplib2 import Http
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
http = Http()
credentials.authorize(http)
This has worked in the past for me and for others. Now I get this ImportError:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-deffc94100d1> in <module>()
1 from httplib2 import Http
2 from oauth2client.client import GoogleCredentials
----> 3 credentials = GoogleCredentials.get_application_default()
4 http = Http()
5 credentials.authorize(http)
/usr/local/lib/python2.7/dist-packages/oauth2client/client.pyc in get_application_default()
1202 GoogleCredentials.get_application_default().
1203
-> 1204 Args:
1205 access_token: string, access token.
1206 client_id: string, client identifier.
/usr/local/lib/python2.7/dist-packages/oauth2client/client.pyc in _get_implicit_credentials(cls)
1187 """
1188
-> 1189 NON_SERIALIZED_MEMBERS = (
1190 frozenset(['_private_key']) |
1191 OAuth2Credentials.NON_SERIALIZED_MEMBERS)
/usr/local/lib/python2.7/dist-packages/oauth2client/client.pyc in _implicit_credentials_from_gce()
1123
1124 def _in_gae_environment():
-> 1125 """Detects if the code is running in the App Engine environment.
1126
1127 Returns:
/usr/local/lib/python2.7/dist-packages/oauth2client/client.pyc in _get_application_default_credential_GCE()
1378 """Get the Application Default Credentials for the current environment.
1379
-> 1380 Raises:
1381 ApplicationDefaultCredentialsError: raised when the credentials
1382 fail to be retrieved.
ImportError: No module named gce
Has something changed? has a module that was previously named "gce" been renamed? do I need to create credentials? (The project has both a default App Engine service account and a default Compute Engine service account, and has all of the APIs that I think might need to be enabled already enabled.)
20-apr-2016 UPDATE: After not trying to repeat this for about a month, I was looking at this again yesterday. The first time I tried to re-run the same notebook I was working with last month, I needed to take out the fix I had added in as a result of this issue in order to get it to work. But today that same code would again not work. In the mean-time I noticed that the recommendations had been updated, so I am now going to walk through the recommended approaches.
!pip show google-api-python-client
---
Name: google-api-python-client
Version: 1.5.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: httplib2, uritemplate, six, oauth2client
Looking here the specific versions required seem to be: httplib2>=0.8,<1; any oauth2client; six>=1.6.1,<2; and uritemplate>=0.6,<1. (The change to allow earlier oauth2client versions seems to have been committed on Mar 14, but Pypi shows the most recent version as 1.5.0 uploaded on Feb 20, which agrees with the Releases page which says that 1.5.0 was released on Feb 19, which may have been when this problem originally appeared although I didn't notice it for a few weeks.)
I have not been able to get much further in trying out the 3 options described by Anthonios because I repeatedly get "Connection failed" or other errors when trying to use Datalab. I will try to update this issue again soon.