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

时间:2018-09-12 03:23:13

标签: python-3.x google-cloud-platform google-cloud-datastore

我按照python Google Cloud Datastore本教程中给出的说明进行了本地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文件中,所以我不知道要安装哪个模块。

2 个答案:

答案 0 :(得分:1)

这是一个丢失(或损坏)的依赖项问题。可以通过安装google-cloud-storage来解决。

pip install google-cloud-storage

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

答案 1 :(得分:1)

听起来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
>>>