1

I am following the google cloud intro for python apps.

I am using a simple flask app similar to the example in the page with the addition of using the psycopg2 python library for postgres.

When run under the google SDK dev_appserver.py script, the stack below is thrown. I believe that what is happening is that the dev_appserver.py script is acting as a sandbox and not allowing the native code aspects of psycopg2 to be imported - presumably as native code is not allowed on the google python app infra (_psycopg2.pyd is in the psycopg2 install)

What I do not understand however is that postgres is in beta for google cloud SQL and a similar guide from Google indicates that psycopg2 is supported.

But I'm getting the following error:

ERROR    2018-02-20 02:55:51,746 wsgi.py:263]
Traceback (most recent call last):
  File "C:\Users\grant\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "C:\Users\grant\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "C:\Users\grant\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "C:\Users\grant\PycharmProjects\graph\google_app.py", line 2, in <module>
    from db.store import Store
  File "C:\Users\grant\PycharmProjects\graph\db\store.py", line 2, in <module>
    from db.objects import Objects
  File "C:\Users\grant\PycharmProjects\graph\db\objects.py", line 5, in <module>
    from psycopg2.extras import execute_values
  File "C:\Users\grant\PycharmProjects\graph\3rd\psycopg2\__init__.py", line 50, in <module>
    from psycopg2._psycopg import (                     # noqa
  File "C:\Users\grant\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\runtime\sandbox.py", line 1093, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named psycopg2._psycopg
INFO     2018-02-19 21:55:51,757 module.py:835] default: "GET /gui HTTP/1.1" 500 -
Taku
  • 31,927
  • 11
  • 74
  • 85
  • fwiw, this is not just happening when running locally via dev_appserver.py, deploying to the google cloud gives the same error - consistency is good. – Grant McKenzie Feb 20 '18 at 04:48
  • Could you add the requirements.txt? Also, are you sure the library is properly installed in your dev environment? Found this [thread](https://stackoverflow.com/questions/36103034/importerror-no-module-named-psycopg2-psycopg) that'd be worth reading – Miller G. Feb 28 '18 at 13:14

0 Answers0