1

I'm facing an issue where google.appengine and google.cloud python modules are under different directories named google

Their following paths are as below:

1st Path: C:\Users\MohammedT\Desktop\dsapp\sitepackages\dev\google_appengine

api_server.py
appcfg.py
backends_conversion.py
BUGS
bulkloader.py
bulkload_client.py
demos
dev_appserver.py
download_appstats.py
endpointscfg.py
gen_protorpc.py
google    --> Directory 1 where appengine module resides
lib
LICENSE
new_project_template
php
php_cli.py
README
RELEASE_NOTES
remote_api_shell.py
run_tests.py

2nd Path: C:\Users\MohammedT\Desktop\datastore\dsenv\Lib\site-packages

enum
enum34-1.1.6.dist-info
future
future-0.16.0.dist-info
futures-3.2.0.dist-info
gapic_google_cloud_datastore_v1-0.15.3-py2.7-nspkg.pth
gapic_google_cloud_datastore_v1-0.15.3.dist-info
gapic_google_cloud_error_reporting_v1beta1-0.15.3-py2.7-nspkg.pth
gapic_google_cloud_error_reporting_v1beta1-0.15.3.dist-info
gapic_google_cloud_logging_v2-0.91.3-py2.7-nspkg.pth
gapic_google_cloud_logging_v2-0.91.3.dist-info
google    ------------> Directory 2 where other other modules resides
googleapiclient
googleapis_common_protos-1.5.3-py2.7-nspkg.pth
googleapis_common_protos-1.5.3.dist-info
google_api_core-0.1.3-py3.6-nspkg.pth
google_api_core-0.1.3.dist-info
google_api_python_client-1.6.4.dist-info

Can I achieve this without moving them to a common directory?

I have set the python path to point at both of these directories. I'm currently able to import from Directory 2 but cannot import from Directory 1

Tameem
  • 408
  • 7
  • 19
  • 1
    If this is all part of a package you are developing, you may want to review the [docs](https://docs.python.org/3.6/tutorial/modules.html#packages) for some guidance. – pstatix Jan 10 '18 at 12:57
  • 1
    Possible duplicate of [Using Two Python Libraries with Conflicting Names](https://stackoverflow.com/questions/41399303/using-two-python-libraries-with-conflicting-names) – new name Jan 10 '18 at 13:48

1 Answers1

0

You can load each module from its path. In Python 2 use:

import imp

foo = imp.load_source('module.name', '/path/to/file.py')
foo.MyClass()

additional detail in this lovely answer: How to import a module given the full path?

rvictordelta
  • 630
  • 2
  • 8
  • 23