I want to use two Python libraries (Google Cloud Library and their Cloud SDK ) in one application, but they have conflicting names (they both use google in their base import names and do not use relative imports within themselves). How can I use them in one application?
Changing the library code to use proper relative imports is impractical. Also, I know that I can use virtualenv to access these libraries from individual python applications, but how do I access them from the same python application?
Naming Conflict Details
Here are some of the import details. When I import a module from the Cloud Library (I run import google.cloud.datastore ), there is an exception due to another import inside this library:
>>> import libs.google.cloud.datastore Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\[ProjectDIR]\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 library is trying to do absolute imports, not relative ones. The reason the Google cloud library cannot import google.cloud.datastore.batch is because google already defined in the SDK, there is a name conflict:
>>> print google.__path__ ['C:\\Program Files (x86)\\Google\\Cloud SDK\\google-cloud-sdk\\platform\\google_appengine\\google']
Since the cloud library uses absolute imports, and the google name is already defined in the SDK, import is not possible.
python google-app-engine virtualenv python-import google-cloud-platform
speedplane
source share