Using Google Cloud Client Library and Google App E

2019-07-28 04:47发布

问题:

I am trying to use the Google Cloud Client Library on Google App Engine. However, the Cloud Client Library and the App Engine SDK use google as an import name, and there are naming conflicts. How do I get them to work together?

When I try importing a Google Cloud Client Library module, I get the following error:

     >> import google.cloud.datastore
     Traceback (most recent call last):
       File "<console>", line 1, in <module>
       File "C:\[...]\libs\google\cloud\datastore\__init__.py", line 52, in <module>
         from google.cloud.datastore.batch import Batch
     ImportError: No module named cloud.datastore.batch

The reason this import error occurs is because the name google has already been imported from the App Engine SDK. This can be confirmed by running the command:

     >>> print google.__path__
     ['C:\\Program Files (x86)\\Google\\Cloud SDK\\google-cloud-sdk\\ platform\\google_appengine\\google']

Notice that the path points to the SDK.

Any ideas on how to resolve this name conflict?