代码之家  ›  专栏  ›  技术社区  ›  Sam

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

  •  2
  • Sam  · 技术社区  · 6 年前

    Google Cloud Datastore python测试教程 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 回复  |  直到 6 年前
        1
  •  1
  •   Dustin Ingram    6 年前

    听起来像是 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
    >>>
    
        2
  •  1
  •   Sam    6 年前

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

    pip install google-cloud-storage
    

    谷歌应该把这个添加到 datastore 的依赖树,让我们的生活更轻松。