I'm writing a Google App Engine project in Python with Flask. Here's my directory structure for a Hello, World! app (contents of third party libraries ommitted for 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
from myapp import app
run_wsgi_app(app)
And myapp/__init__.py
:
from flask import Flask
app = Flask("myapp")
@app.route("/")
def hello():
return "Hello, World!"
Since Flask has so many dependencies and sub dependencies, I thought it would be nice to tidy up the directory structure by putting all the third party code in a subdirectory (say project_root/lib
). Of course, then sys.path
doesn't know where to find the libraries.
I've tried the solutions in How do you modify sys.path in Google App Engine (Python)?, but that doesn't seem to work. I've also tried changing from flask import Flask
to from lib/flask import Flask
, to no avail. Is there a good way to do this?