我试图在GAE上实现一个cron作业,它将查看云存储桶中的csv文件并将其加载到BigQuery表中。代码在我的mac上工作正常(macOS Sierra,10.12.6)。
但是,当我通过gcloud app deploy app.yaml
在GAE上部署应用程序并使用gcloud app deploy cron.yaml
配置cron作业时,cron作业将失败:
from google.cloud import bigquery
。我试过this solution无济于事。知道我做错了吗?
以下是来自cron日志的完整错误消息。
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
作为参考,我在python版本2.7.10的虚拟环境中工作。我的app.yaml
是:
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /cronjobs
script: uploadBQ.py
login: admin
- url: /.*
script: main.app
cron.yaml
的内容:
cron:
- description: cron to BQ
url: /cronjobs
schedule: every 15 minutes from 10:20 to 11:20
requirements.txt的内容(通过lib
安装在pip install -r requirements.txt -t lib
文件夹中):
google-api-python-client
google-cloud
appengine_config.py
# appengine_config.py
from google.appengine.ext import vendor
# Add any libraries install in the "lib" folder.
vendor.add('lib')
答案 0 :(得分:0)
来自BigQuery Client Libraries(在PYTHON
标签上):
安装客户端库
pip install --upgrade google-cloud-bigquery
请注意,这些说明适用于通用python应用程序,我只是将其包含在库的名称中。
因此,您需要将google-cloud-bigquery
添加到requirements.txt
文件中,在GAE上重新运行需求安装和应用部署。