【问题标题】:Import Error: No module named 'google.cloud' on ApacheBeamImporterror:Apache Beam 上没有名为“google.cloud”的模块
【发布时间】:2020-01-16 07:56:59
【问题描述】:

导入 apache beam 的 google 数据存储 api 时出现导入错误。我的 Windows 10 64 位系统上安装了一个版本的 Python 3。

有人可以帮助我吗?我试图解决它,但我不能

# -*- coding: utf-8 -*-
import apache_beam as beam
from apache_beam.io.gcp.datastore.v1new.datastoreio import ReadFromDatastore, WriteToDatastore
from apache_beam.options.pipeline_options import GoogleCloudOptions
from apache_beam.options.pipeline_options import PipelineOptions

我的错误信息是这样的

Traceback (most recent call last):
  File "C:\Work\test.py", line 3, in <module>
    from apache_beam.io.gcp.datastore.v1new.datastoreio import ReadFromDatastore, WriteToDatastore
  File "C:\Work\VENV\venv\lib\site-packages\apache_beam\io\gcp\datastore\v1new\datastoreio.py", line 40, in <module>
    from apache_beam.io.gcp.datastore.v1new import helper
  File "C:\Work\VENV\venv\lib\site-packages\apache_beam\io\gcp\datastore\v1new\helper.py", line 33, in <module>
    from google.cloud import environment_vars
ModuleNotFoundError: No module named 'google.cloud'

这是点子列表

Package                  Version
------------------------ ----------
apache-beam              2.17.0
avro-python3             1.9.1
cachetools               4.0.0
certifi                  2019.11.28
chardet                  3.0.4
crcmod                   1.7
dill                     0.3.0
docopt                   0.6.2
fastavro                 0.21.24
future                   0.18.2
google-api-core          1.16.0
google-api-python-client 1.7.11
google-auth              1.10.1
google-auth-httplib2     0.0.3
googleapis-common-protos 1.51.0
grpcio                   1.26.0
hdfs                     2.5.8
httplib2                 0.12.0
idna                     2.8
mock                     2.0.0
numpy                    1.18.1
oauth2client             3.0.0
pbr                      5.4.4
pip                      19.0.3
protobuf                 3.11.2
pyarrow                  0.15.1
pyasn1                   0.4.8
pyasn1-modules           0.2.8
pydot                    1.4.1
pymongo                  3.10.1
pyparsing                2.4.6
python-dateutil          2.8.1
pytz                     2019.3
requests                 2.22.0
rsa                      4.0
setuptools               40.8.0
six                      1.14.0
uritemplate              3.0.1
urllib3                  1.25.7

请帮我解决我的问题。之前谢谢你

【问题讨论】:

标签: python google-cloud-datastore google-cloud-dataflow


【解决方案1】:

我安装了 apache-beam[gcp] 并且运行良好。

【讨论】:

    【解决方案2】:

    “google-cloud”-Pacakge 丢失。

    运行:

    pip install google-cloud
    

    【讨论】:

    • 我试过并安装了:google-cloud 0.34.01。但它不起作用。同样的错误ModuleNotFoundError: No module named 'google.cloud' 仍然出现。
    【解决方案3】:

    您需要在 ApacheBeam 上的选项中添加“--requirements_file”标志。

    如下

    options = MyOptions(flags = ["--requirements_file", "./requirements.txt"])
    

    【讨论】:

    • 谢谢。我在使用 requirements.txt 安装 google-cloud-datastore 后解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-07
    • 2020-12-18
    • 1970-01-01
    • 2021-02-03
    • 2019-07-16
    • 1970-01-01
    • 2017-03-21
    相关资源
    最近更新 更多