Google Cloud Datastore python 本地开发人员找不到数据存储模块

Google Cloud Datastore python local dev can't find datastore module

我在本地遵循了此 Google Cloud Datastore tutorial in python to test Datastore 中给出的说明。当我 运行 此代码时:

from google.cloud import datastore

client = datastore.Client()

我收到以下错误:

from google.cloud import datastore
ModuleNotFoundError: No module named 'google.cloud'

我安装了google-cloud-datastore,但问题仍然存在。

似乎是缺少依赖的问题,但是我不知道要安装什么模块,因为我在 requirements.txt 文件中安装了所有内容。

这是一个缺失(或损坏)的依赖项问题。它通过安装 google-cloud-storage.

修复
pip install google-cloud-storage

Google 应该将它添加到 datastore 的依赖树中,以使我们的生活更轻松。

听起来 google-cloud-datastore 要么没有正确安装,要么没有安装在您尝试从中导入它的同一环境中。

我可以在空环境中安装 google-cloud-datastore 包,然后导入它:

/tmp $ python -m venv env

/tmp $ source env/bin/activate

(env) /tmp $ pip freeze

(env) /tmp $ pip install google-cloud-datastore==1.7.0
Collecting google-cloud-datastore==1.7.0
  ...lots of output...
Successfully installed cachetools-2.1.0 certifi-2018.8.24 chardet-3.0.4 google-api-core-1.4.0 google-auth-1.5.1 google-cloud-core-0.28.1 google-cloud-datastore-1.7.0 googleapis-common-protos-1.5.3 grpcio-1.15.0 idna-2.7 protobuf-3.6.1 pyasn1-0.4.4 pyasn1-modules-0.2.2 pytz-2018.5 requests-2.19.1 rsa-3.4.2 six-1.11.0 urllib3-1.23

(env) /tmp $ pip freeze
cachetools==2.1.0
certifi==2018.8.24
chardet==3.0.4
google-api-core==1.4.0
google-auth==1.5.1
google-cloud-core==0.28.1
google-cloud-datastore==1.7.0
googleapis-common-protos==1.5.3
grpcio==1.15.0
idna==2.7
protobuf==3.6.1
pyasn1==0.4.4
pyasn1-modules==0.2.2
pytz==2018.5
requests==2.19.1
rsa==3.4.2
six==1.11.0
urllib3==1.23

(env) /tmp $ python
Python 3.7.0 (default, Jul 30 2018, 11:52:05)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.cloud import datastore
>>>