0

I have a basic REST backend in Python that I am trying to deploy to Google App Engine. However, after following the instructions both here and here, my script cannot import some of my third party libraries.

I've installed all of the libraries in the lib/ directory, I've added 'appengine_config.py' to add lib to the path so the libraries should be discovered yet requests always fail with

Traceback (most recent call last):
(/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/cgi.py:122)
  File "/base/data/home/apps/myapp/myapp/Rest.py", line 2, in <module>
    import flask_sqlalchemy
ImportError: No module named flask_sqlalchemy

I have this app.yaml

runtime: python27
api_version: 1
threadsafe: false
service: feedback-backend

handlers:
  - url: /*
    script: Rest.py

beta_settings:
    cloud_sql_instances: feedbackmysql:us-east4:feedback-mysql

skip_files:
  venv/*

and this requirements.txt

aniso8601==1.3.0
click==6.7
Flask==0.12.2
Flask-RESTful==0.3.6
Flask-Restless==0.17.0
Flask-SQLAlchemy==2.3.2
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
mimerender==0.6.0
pep8==1.7.0
PyMySQL==0.7.11
python-dateutil==2.6.1
python-mimeparse==1.6.0
pytz==2017.2
six==1.11.0
SQLAlchemy==1.1.14
virtualenv==15.1.0
Werkzeug==0.12.2
ThisIsNoZaku
  • 2,213
  • 2
  • 26
  • 37
  • what is your `requirements.txt` looks like? – yash Oct 25 '17 at 03:00
  • @ykisga FYI requirements.txt isn't part of App Engine's library handling. – BrettJ Oct 25 '17 at 03:45
  • 2
    You linked to a standard environment topic and a flexible environment topic, which environment are you using? You should post your complete `app.yaml` file. – BrettJ Oct 25 '17 at 03:46
  • @ThisIsNoZaku See also https://stackoverflow.com/questions/45842772/how-to-tell-if-a-google-app-engine-documentation-page-applies-to-the-standard-or – Dan Cornilescu Oct 25 '17 at 14:38
  • @BrettJ It's a standard environment, as far as I can tell. When I'd last done anything with GAE I don't think the different environments were a thing. – ThisIsNoZaku Oct 25 '17 at 23:09
  • Where is the `lib` dir located relative to the `Rest.py` file? – Dan Cornilescu Oct 26 '17 at 03:12
  • Side note: you shouldn't reference the `Rest.py` file in `app.yaml`, you should reference a variable representing a WSGI application defined in `Rest.py`, typically called `app`, like this: `script: Rest.app`. Donno if related to the import error, tho. See `script` row in the [Handlers element](https://cloud.google.com/appengine/docs/standard/python/config/appref#handlers_element) table. – Dan Cornilescu Oct 26 '17 at 03:14
  • Have you gotten your application running in the `dev_appserver`? That might help you debug – Charles Oct 26 '17 at 04:54
  • @DanCornilescu Rest.py and lib/ are both in the root. – ThisIsNoZaku Oct 26 '17 at 05:24
  • @Charles The dev server fails with a 500 error same as when deployed, but without any console errors. – ThisIsNoZaku Oct 26 '17 at 05:24
  • @ThisIsNoZaku: in the root of the app or of the service? (Or do you have all services mixed together right in the app root?) – Dan Cornilescu Oct 26 '17 at 05:53
  • A shot in the dark - maybe you should add the `skip_files` default patterns as well? Otherwise it can cause quite obscure failures, see https://stackoverflow.com/questions/46311440/appengine-no-module-named-pyasn1-compat-binary/46413051#46413051 – Dan Cornilescu Oct 26 '17 at 05:59
  • Is this the 1st import from the `lib` dir in your code or you have others before it which work fine? – Dan Cornilescu Oct 26 '17 at 06:01
  • How are you launching the devserver? I never saw a 500 response from it without logs... – Dan Cornilescu Oct 26 '17 at 06:03
  • @ThisIsNoZaku try adding `--dev_appserver_log_level=debug` when you run local devserver to get code errors – Charles Oct 26 '17 at 08:07

0 Answers0