无法使用google-cloud-pubsub-0.37.2在python 2.7中导入WriteToPubSub

问题描述 投票:0回答:2

我试图在从csv读取并编写一些转换后利用写入pubsbub,然而,一旦我到了需要开始使用pubsub的点,我无法导入。这是我正在导入的内容:

from __future__ import absolute_import
import apache_beam as beam
from datetime import datetime
from beam_utils.sources import CsvFileSource
from apache_beam.io import ReadFromText
from apache_beam.io import WriteToText
from apache_beam.io.gcp.pubsub import PubsubMessage
from apache_beam.io.gcp.pubsub import ReadFromPubSub
from apache_beam.io.gcp.pubsub import ReadStringsFromPubSub
from apache_beam.io.gcp.pubsub import WriteStringsToPubSub
from apache_beam.io.gcp.pubsub import WriteToPubSub
#from apache_beam.io.gcp.pubsub import WriteToPubSub
from apache_beam.io.gcp.pubsub import _PubSubSource
from apache_beam.metrics import Metrics
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

到目前为止,我认为只有WriteToPubSub和WriteToPubSub失败。

失败看起来像这样:

from apache_beam.io.gcp.pubsub import WriteToPubSub
  ImportError: cannot import name WriteToPubSub

我看到模块已安装:

py -2 -m pip show google-cloud-pubsub
Name: google-cloud-pubsub
Version: 0.26.0
Summary: Python Client for Google Cloud Pub/Sub
Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python
Author: Google Cloud Platform
Author-email: [email protected]
License: Apache 2.0
Location: d:\python27\lib\site-packages
Requires: gapic-google-cloud-pubsub-v1, google-cloud-core, grpcio
Required-by:

升级模块:

Installing collected packages: google-cloud-pubsub
  Found existing installation: google-cloud-pubsub 0.26.0
    Uninstalling google-cloud-pubsub-0.26.0:
      Successfully uninstalled google-cloud-pubsub-0.26.0
Successfully installed google-cloud-pubsub-0.37.2

仍然是同一个问题

我真的很想知道我做错了什么吗?错误的版本?

python-2.7 google-cloud-dataflow apache-beam google-cloud-pubsub
2个回答
0
投票

我怀疑你缺少proto-google-cloud-pubsub-v1==0.15.4。在使用GCP pubsub时,使用pip install --upgrade apache-beam[gcp]安装Apache Beam以及所有必需的依赖项。

参考:https://cloud.google.com/dataflow/docs/quickstarts/quickstart-python#get-the-apache-beam-sdk


0
投票

WriteToPubSub属于apache_beam。因此,检查您的pip freeze安装并查找您的apache梁版本。例如:apache-beam==2.11.0。如果没有,请尝试安装pip install apache-beam[gcp],因为它将包含使用Google Cloud Dataflow运行程序等功能所需的依赖项。有关更多信息,您可以查看此link

希望能帮助到你。

© www.soinside.com 2019 - 2024. All rights reserved.