我试着在读完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失败了。
失败看起来是这样的:
从apache_beam.io.gcp.pubsub导入WriteToPubSub ImportError:无法导入名称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: jjg+google-cloud-python@google.com
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仍然是同样的问题
真的很想知道我到底做错了什么?错误的版本?
发布于 2018-08-27 01:03:32
我怀疑你错过了proto-google-cloud-pubsub-v1==0.15.4。在使用GCP时,请使用pip install --upgrade apache-beam[gcp]安装Apache和所有所需的依赖项。
参考资料:https://cloud.google.com/dataflow/docs/quickstarts/quickstart-python#get-the-apache-beam-sdk
发布于 2019-03-25 14:50:31
WriteToPubSub属于apache_beam。因此,检查您的pip freeze安装并查找apache版本。例如:apache-beam==2.11.0。如果没有,请尝试安装pip install apache-beam[gcp],因为它将包括使用Google运行程序等特性所需的依赖项。有关更多信息,您可以查看此链接。
希望能帮上忙。
https://stackoverflow.com/questions/52021288
复制相似问题