2
votes

I followed the instructions given in this Google Cloud Datastore tutorial in python to test Datastore locally. When I run this code:

from google.cloud import datastore

client = datastore.Client()

I get the following error:

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

I installed google-cloud-datastore, yet the problem persists.

It seems like a missing dependency problem, yet I don't know what module to install since I installed everything in the requirements.txt file.

2
It sounds like the google-cloud-datastore either didn't get properly installed or isn't installed in the same environment you're trying to import it in. Can you include the output of pip freeze? - Dustin Ingram

2 Answers

1
votes

It sounds like the google-cloud-datastore either didn't get properly installed or isn't installed in the same environment you're trying to import it from.

From an empty environment, I can install the google-cloud-datastore package, and then be able to import it:

/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
>>>
1
votes

This is a missing (or broken) dependency problem. It's fixed by installing google-cloud-storage.

pip install google-cloud-storage

Google should have added this to datastore's dependency tree to make our lives easier.