在Google App Engine Flex上运行Apache Beam时,'module'对象没有属性'WriteToBigQuery'

时间:2018-02-09 15:52:46

标签: python google-app-engine google-bigquery apache-beam apache-beam-io

我有一个Google App Engine触发Cloud DataFlow管道。这个管道应该将最终的PCollection写入Google BigQuery,但我找不到安装正确的apache_beam.io依赖的方法。

我在本地运行Apache Beam版本2.2.0。

项目结构遵循this blog post的代码。

这是相关的代码:

"WriteToBigQuery" >> beam.io.WriteToBigQuery(
            ("%s:%s.%s" % (PROJECT, DATASET, TABLE)),
            schema=TABLE_SCHEMA,
            create_disposition=beam.io.BigQueryDisposition.CREATE_IF_NEEDED,
            write_disposition=beam.io.BigQueryDisposition.WRITE_APPEND
        )

当我在本地运行此代码时,会正确调用beam.io.WriteToBigQuery()。它是从我的虚拟环境apache_beam/io/gcp/bigquery.py中获取的。

但我无法在部署的应用附带的lib文件夹中安装此依赖项。

即使我有一个包含apache-beam[gcp]==2.2.0的需求文件作为要求,当我运行pip install -r requirements.txt -t lib时,下载到我的apache_beam/io/gcp/bigquery.py文件夹的lib也不包含类WriteToBigQuery,然后在Google App Engine上运行应用时出现错误'module' object has no attribute 'WriteToBigQuery'

有没有人知道我如何才能获得正确的bigquery.py

1 个答案:

答案 0 :(得分:0)

这不是立即显而易见的,但是要在App Engine中运行,如blog post中所述,有必要创建一个setup.py(即使您已经拥有requirements.txt),并在运行管道时通过--setup_file ./setup.py命令行选项指向它。