I am trying to run a BigQuery query from Google AppEngine (deployed) using Python 2.7, but I see this error in StackDriver Error Reporting:
ImportError: no module named cloud
This is my code (main.py):
from __future__ import absolute_import import webapp2 from google.cloud import bigquery class MainPage(webapp2.RequestHandler): def get(self):
This is my (app.yaml):
runtime: python27 api_version: 1 threadsafe: true handlers: - url: /.* script: main.app
The error message makes me assume that the BigQuery library is not being imported. However, if this code is deployed to AppEngine, should the library not already be installed in AppEngine by default?
Trying to solve a problem
Attempt # 1
I found this post that relates to a similar issue. It was suggested to add this line to the top of the file. I added a line to my file, but the problem still exists:
from __future__ import absolute_import
Source: No module named cloud when using a lot of google.cloud requests
Attempt # 2
I installed the BigQuery client locally on my laptop:
pip install google-cloud-bigquery==0.22.1
I also installed the same client in the "lib" folder to load it into AppEngine after it was deployed:
pip install --target='lib' google-cloud-bigquery==0.22.1
In the latter case, you also need to create a file called "appengine_config.py" with this content:
# appengine_config.py from google.appengine.ext import vendor
Source: https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27
However, this attempt did not work either. The error message has changed to the following:
*File "/base/data/home/apps/p~experimenting-1130/2.400173726395247238/lib/httplib2/__init__.py", line 352: print('%s:' % h, end=' ', file=self._fp) ^ SyntaxError: invalid syntax at <module> (/base/data/home/apps/p~experimenting-1130/2.400173726395247238/lib/google_auth_httplib2.py:23) at <module> (/base/data/home/apps/p~experimenting-1130/2.400173726395247238/lib/google/cloud/_helpers.py:31) at <module> (/base/data/home/apps/p~experimenting-1130/2.400173726395247238/lib/google/cloud/bigquery/_helpers.py:21) at <module> (/base/data/home/apps/p~experimenting-1130/2.400173726395247238/lib/google/cloud/bigquery/__init__.py:26) at get (/base/data/home/apps/p~experimenting-1130/2.400173726395247238/main.py:75) at dispatch (/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py:545) at dispatch (/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py:547) at __call__ (/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py:1077) at default_dispatcher (/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py:1253) at __call__ (/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py:1505) at __call__ (/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py:1511)*
How can I import the BigQuery library correctly in AppEngine (deployed)?
Thank you for your help.