【问题标题】:How to fix google sub module import error?如何修复谷歌子模块导入错误?
【发布时间】:2020-10-05 22:58:00
【问题描述】:

我正在尝试在云 sdk 中运行以下命令以向云 IOT 发送命令

python3 main.py --send_command="$RESPONSE" --registry=REGISTRY NAME --device=DEVICE NAME --cloud_region=europe-west1 --project_id=PROJECT ID send-command

我收到以下错误消息。

Traceback (most recent call last):
  File "main.py", line 37, in <module>
    from google.api_core.exceptions import AlreadyExists
ModuleNotFoundError: No module named 'google

我尝试了以下解决方法,但没有成功。

pip install --upgrade google-api-core
pip install google-cloud
pip install google-cloud-vision

我错过了任何图书馆吗?

Python 版本 - Python 3.8.3

【问题讨论】:

    标签: python python-3.x google-cloud-sdk google-cloud-iot


    【解决方案1】:

    如果您还没有并且愿意考虑使用virtualenv,它可能有助于(!)解决问题,因为它提供了一个“洁净室”:

    python3 -m venv venv
    source venv/bin/activate
    

    然后检查当前模块:

    pip3 freeze
    

    不返回任何安装模块

    然后:

    pip3 install google-api-core
    pip3 install google-cloud-vision
    pip3 freeze
    

    或者,最好创建requirements.txt

    google-api-core==1.21.0
    google-cloud-vision==1.0.0
    

    还有:

    pip3 install --requirement ./requirements.txt
    pip3 freeze
    

    返回:

    cachetools==4.1.0
    certifi==2020.4.5.2
    chardet==3.0.4
    google-api-core==1.21.0
    google-auth==1.18.0
    google-cloud-vision==1.0.0
    googleapis-common-protos==1.52.0
    idna==2.9
    protobuf==3.12.2
    pyasn1==0.4.8
    pyasn1-modules==0.2.8
    pytz==2020.1
    requests==2.24.0
    rsa==4.6
    six==1.15.0
    urllib3==1.25.9
    

    注意列表和版本会改变

    然后检查导入将成功:

    python3 -c "from google.api_core.exceptions import AlreadyExists"
    

    【讨论】:

      猜你喜欢
      • 2022-07-22
      • 2018-08-10
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      相关资源
      最近更新 更多