简体   繁体   中英

Python sys.path.append with modules shadowing each other

I am trying to import module named "google" from a custom folder (inside google_appengine folder).

import sys
sys.path.append("/home/sashko/WebProgramming/google_appengine")
import google.appengine.api

But there is already a module named "google" in sys.path:

import google
print google.__path__

['/usr/lib/python2.7/dist-packages/google']

And it shadows module "google" from the custom folder. What would you suggest in such cases?

Insert the path at the start of sys.modules :

sys.path.insert(0, "/home/sashko/WebProgramming/google_appengine")

Now the google_appengine directory will be consulted before the dist-packages location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM