【问题标题】:beam dataflow python name 'PipelineOptions' is not defined未定义光束数据流 python 名称“PipelineOptions”
【发布时间】:2017-10-07 21:48:23
【问题描述】:

我想创建非常简单的管道,但一开始就卡住了。这是我的代码:

import apache_beam as beam
options = PipelineOptions()
google_cloud_options = options.view_as(GoogleCloudOptions)
google_cloud_options.project = 'myproject'
google_cloud_options.job_name = 'mypipe'
google_cloud_options.staging_location = 'gs://mybucket/staging'
google_cloud_options.temp_location = 'gs://mybucket/temp'
options.view_as(StandardOptions).runner = 'DataflowRunner'

产生错误:

NameError: name 'PipelineOptions' is not defined

【问题讨论】:

    标签: python pipeline apache-beam dataflow


    【解决方案1】:

    模块代码已从 apache_beam.utils 更改为 apache_beam.option

    你现在应该使用:

    from apache_beam.options.pipeline_options import PipelineOptions
    from apache_beam.options.pipeline_options import SetupOptions
    from apache_beam.options.pipeline_options import GoogleCloudOptions
    from apache_beam.options.pipeline_options import StandardOptions
    

    官方文档在这里:https://beam.apache.org/releases/pydoc/2.0.0/_modules/apache_beam/options/pipeline_options.html

    【讨论】:

      【解决方案2】:

      您需要添加一些额外的导入才能使示例正常工作:

      from apache_beam.io import ReadFromText
      from apache_beam.io import WriteToText
      from apache_beam.metrics import Metrics
      from apache_beam.utils.pipeline_options import PipelineOptions
      from apache_beam.utils.pipeline_options import SetupOptions
      from apache_beam.utils.pipeline_options import GoogleCloudOptions
      from apache_beam.utils.pipeline_options import StandardOptions
      

      【讨论】:

        【解决方案3】:
        from apache_beam.pipeline import PipelineOptions
        options = PipelineOptions()
        

        【讨论】:

        • 虽然此代码可能会回答问题,但提供有关它如何和/或为什么解决问题的额外上下文将提高​​答案的长期价值。
        猜你喜欢
        • 1970-01-01
        • 2020-06-27
        • 2018-08-06
        • 2020-08-01
        • 2021-12-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多