【问题标题】:Module object has no attribute BigqueryV2 - Local Apache Beam模块对象没有属性 BigqueryV2 - 本地 Apache Beam
【发布时间】:2017-03-12 13:27:56
【问题描述】:

我正在尝试使用 Apache Beam 使用 Beam 为 Google BigQuery 提供的 I/O API 在本地 (Sierra) 运行管道。

我按照Beam Python quickstart 的建议使用 Virtualenv 设置了我的环境,我可以运行 wordcount.py 示例。我还可以使用beam.Createbeam.ParDo 正确运行自定义管道。

但我无法使用 BigQuery I/O 运行管道。知道我做错了什么吗?

python脚本如下。

import apache_beam as beam
from apache_beam.utils.pipeline_options import PipelineOptions
from apache_beam.io import WriteToText


class MyDoFn(beam.DoFn):
  def process(self, element):
    return element


def run():
  opts = {
    'project': 'gc-project-name'
  }
  p = beam.Pipeline(options=PipelineOptions(**opts))

  input_query = "SELECT name FROM `gc-project-name.dataset_name.table_name`"

  (p
   | beam.io.Read(beam.io.BigQuerySource(query=input_query))
   | beam.ParDo(MyDoFn())
   | beam.io.WriteToText('output.txt')
  )

  result = p.run()
  result.wait_until_finish()

if __name__ == '__main__':
  run()

当我运行它时,我得到以下错误。

WARNING:root:Task failed: Traceback (most recent call last):
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/runners/direct/executor.py", line 300, in __call__
result = evaluator.finish_bundle()
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/runners/direct/transform_evaluator.py", line 208, in finish_bundle
with self._source.reader() as reader:
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/io/gcp/bigquery.py", line 590, in __enter__
self.client = BigQueryWrapper(client=self.test_bigquery_client)
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/io/gcp/bigquery.py", line 682, in __init__
self.client = client or bigquery.BigqueryV2(
AttributeError: 'module' object has no attribute 'BigqueryV2'
Traceback (most recent call last):
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/runners/direct/executor.py", line 300, in __call__
result = evaluator.finish_bundle()
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/runners/direct/transform_evaluator.py", line 208, in finish_bundle
with self._source.reader() as reader:
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/io/gcp/bigquery.py", line 590, in __enter__
self.client = BigQueryWrapper(client=self.test_bigquery_client)
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/io/gcp/bigquery.py", line 682, in __init__
self.client = client or bigquery.BigqueryV2(
AttributeError: 'module' object has no attribute 'BigqueryV2'
WARNING:root:A task failed with exception.
 'module' object has no attribute 'BigqueryV2'
Traceback (most recent call last):
  File "frombigquery.py", line 54, in <module>
run()
  File "frombigquery.py", line 51, in run
result.wait_until_finish()
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/runners/direct/direct_runner.py", line 157, in wait_until_finish
self._executor.await_completion()
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/runners/direct/executor.py", line 335, in await_completion
self._executor.await_completion()
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/runners/direct/executor.py", line 300, in __call__
result = evaluator.finish_bundle()
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/runners/direct/transform_evaluator.py", line 208, in finish_bundle
with self._source.reader() as reader:
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/io/gcp/bigquery.py", line 590, in __enter__
self.client = BigQueryWrapper(client=self.test_bigquery_client)
  File "/Users/localuser/Virtualenvs/abeam/lib/python2.7/site-packages/apache_beam/io/gcp/bigquery.py", line 682, in __init__
self.client = client or bigquery.BigqueryV2(
AttributeError: 'module' object has no attribute 'BigqueryV2'

【问题讨论】:

  • 运行 pip install google-apitools 解决了这个问题。

标签: python python-2.7 google-cloud-dataflow apache-beam apache-beam-io


【解决方案1】:

在安装 Apache Beam Python SDK 时,您必须添加一个附加选项以使用 Google Cloud Platform 相关依赖项。

pip install dist/apache-beam-*.tar.gz[gcp]

【讨论】:

  • 我已经按照link 设置了环境。我尝试再做一次,每个依赖项都得到Requirement already satisfied,所以我假设这方面一切正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-29
  • 2013-02-13
  • 2010-11-18
  • 2019-01-03
相关资源
最近更新 更多