【发布时间】:2018-03-13 03:49:36
【问题描述】:
我正在尝试在 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
requirement.txt 的内容(通过pip install -r requirements.txt -t lib 安装在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')
【问题讨论】:
-
我无法重现这一点,但堆栈跟踪显示
_ctypes正在通过名为tenacity的模块导入;这似乎是最近的一个变化(并且似乎最近每个 github 都恢复了),所以你可以尝试安装一个旧版本,比如 0.26 甚至 0.25(当前是 0.27;我们使用 0.22),pip install -t lib google-cloud-bigquery==0.26(我'd 建议首先完全重新安装lib中的所有内容,以确保您获得全新安装)。 -
做到了。正如你所说,这确实是一个版本问题。我降级到 0.19 版,它的工作就像一个魅力。有关详细讨论,请参阅github.com/GoogleCloudPlatform/google-cloud-python/issues/2464。谢谢。
标签: python python-2.7 google-app-engine cron google-bigquery