I'm trying to implement a cron job on GAE which will look into a csv file in a cloud storage bucket and load that into a BigQuery table. The code works fine on my mac (macOS Sierra, 10.12.6).
However, when I am deploying the app on GAE through gcloud app deploy app.yaml
and configuring the cron job using gcloud app deploy cron.yaml
, the cron job fails at:
from google.cloud import bigquery
. I have tried this solution to no avail. Any idea what I am doing wrong?
Below is the full error message from cron log.
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/f~gcp-101-181605/20171002t142145.404509292894601117/uploadBQ.py", line 17, in <module>
from google.cloud import bigquery
File "/base/data/home/apps/f~gcp-101-181605/20171002t142145.404509292894601117/lib/google/cloud/bigquery/__init__.py", line 32, in <module>
from google.cloud.bigquery.client import Client
File "/base/data/home/apps/f~gcp-101-181605/20171002t142145.404509292894601117/lib/google/cloud/bigquery/client.py", line 21, in <module>
from google.cloud.bigquery.job import CopyJob
File "/base/data/home/apps/f~gcp-101-181605/20171002t142145.404509292894601117/lib/google/cloud/bigquery/job.py", line 34, in <module>
import google.cloud.future.polling
File "/base/data/home/apps/f~gcp-101-181605/20171002t142145.404509292894601117/lib/google/cloud/future/polling.py", line 23, in <module>
import tenacity
File "/base/data/home/apps/f~gcp-101-181605/20171002t142145.404509292894601117/lib/tenacity/__init__.py", line 28, in <module>
from monotonic import monotonic as now
File "/base/data/home/apps/f~gcp-101-181605/20171002t142145.404509292894601117/lib/monotonic.py", line 41, in <module>
import ctypes
File "/base/data/home/runtimes/python27_experiment/python27_dist/lib/python2.7/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
For reference, I am working in a virtual environment with python version 2.7.10. My app.yaml
is:
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /cronjobs
script: uploadBQ.py
login: admin
- url: /.*
script: main.app
Content of cron.yaml
:
cron:
- description: cron to BQ
url: /cronjobs
schedule: every 15 minutes from 10:20 to 11:20
Contents of requirement.txt (installed on lib
folder through pip install -r requirements.txt -t lib
):
google-api-python-client
google-cloud
Content of appengine_config.py
# appengine_config.py
from google.appengine.ext import vendor
# Add any libraries install in the "lib" folder.
vendor.add('lib')