Search code examples
pythongoogle-app-enginemodulepathgae-module

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?


Solution

  • 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.