python - Creating a lib directory in Google App Engine and adding it to sys.path -
python - Creating a lib directory in Google App Engine and adding it to sys.path -
i'm writing google app engine project in python flask. here's directory construction hello, world! app (contents of 3rd party libraries ommitted brevity's sake):
project_root/ flask/ jinja2/ markupsafe/ myapp/ __init__.py simplejson/ werkzeug/ app.yaml itsdangerous.py main.py
here's main.py
:
from google.appengine.ext.webapp.util import run_wsigi_app myapp import app run_wsgi_app(app)
and myapp/__init__.py
:
from flask import flask app = flask("myapp") @app.route("/") def hello(): homecoming "hello, world!"
since flask has many dependencies , sub dependencies, thought nice tidy directory construction putting 3rd party code in subdirectory (say project_root/lib
). of course, sys.path
doesn't know find libraries.
i've tried solutions in how modify sys.path in google app engine (python)?, doesn't seem work. i've tried changing from flask import flask
from lib/flask import flask
, no avail. there way this?
look @ defining path manipulation in appengine_config.py means path manipulation has performed once.
then move 3rd party files in lib per suggestion. utilize relative path 'lib' either specifying sys.path
sys.path.insert(0,'./lib')
or use
import site site.addsitedir("./lib")
do not utilize absolute paths, won't same when deploy code.
putting lib first can useful, if don't want google supplied version of webob.
python google-app-engine sys.path
Comments
Post a Comment