google app engine - Trouble importing the correct module in python in GAE -
how explicitly tell google app engine (python) import json python standard libraries?
due poorly named file (that can not change or rename @ time) having trouble importing json.
there json.py in same directory file working on. when try:
import json
it imports file in same directory.
is there way can along lines of:
from ../ import json
to import native json library?
edit:
i have tried renaming offending file , replacing uses of file. i'm still not able import json standard lib through gae.
attached error log:
file "/users/admin/blah/dataaccess.py", line 13, in <module> classes import zendesk file "/users/admin/blah/classes/zendesk.py", line 10, in <module> import json file "/users/admin/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 892, in load_module raise importerror('no module named %s' % fullname) importerror: no module named classes.json
please google app engine should looking standard library , not in subdirectory classes
if can't rename module reason, have mess around sys.path
put standard lib in front of current module. make sure fix again after import, though...
import sys sys.path = [r'c:\python27\lib'] + sys.path import json sys.path = sys.path[1:]
alternately, i'm pretty sure imp module has functionality this.
let me clear, though: it better (as others have said) rename module in project directory (e.g. my_json.py
). you're not going have change that many dependencies.
some edits: if cannot find actual path, absolute or otherwise, standard lib, have 2 further options besides renaming thing. can move file you're working on different level in package (so can't see local json.py
). instance, this:
/package __init__.py your_file.py # "import json" should hit std lib. # import local copy, use "from app import json" app/ __init__.py json.py other_thing.py # contains "import json" local copy
if don't want move file, can fake adding file nothing import real json module:
/package __init__.py json_importer.py # contains nothing "import json" app/ __init__.py json.py your_file.py # "from package.json_importer import json" other_thing.py # contains "import json" local copy
Comments
Post a Comment