【问题标题】:No module named api_core.protobuf_helpers. python2.7 and googlecloud没有名为 api_core.protobuf_helpers 的模块。 python2.7和googlecloud
【发布时间】:2019-03-13 13:22:45
【问题描述】:

我正在尝试the following example 使用语言自动检测来测试翻译。

它适用于 python3。

但是在尝试使用 python2.7 时,它会失败并显示以下消息:

python2.7 example.py multi-language
Traceback (most recent call last):
  File "google_example.py", line 295, in <module>
    transcribe_file_with_multilanguage()
  File "google_example.py", line 214, in transcribe_file_with_multilanguage
    from google.cloud import speech_v1p1beta1 as speech
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/speech_v1p1beta1/__init__.py", line 17, in <module>
    from google.cloud.speech_v1p1beta1 import types
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/speech_v1p1beta1/types.py", line 20, in <module>
    from google.api_core.protobuf_helpers import get_messages
ImportError: No module named api_core.protobuf_helpers

pip2 freeze | grep google的输出:

google==2.0.2 
google-api-core==1.8.0
google-auth==1.6.3 
google-cloud-core==0.29.1 
google-cloud-speech==0.36.3 
googleapis-common-protos==1.6.0b9

【问题讨论】:

  • Python 2 和 3 的导入方式不同。你可以在this answer阅读更多关于它的信息。
  • 您可能正在使用google-cloud-speech 库的old version 运行它。你能分享命令pip2 freeze | grep google 的结果吗?并且看在 Guido 的份上,停止使用 Python2.7,距离第一个 Python3 版本发布已有 10 多年了。
  • 这是输出:google==2.0.2 google-api-core==1.8.0 google-auth==1.6.3 google-cloud-core==0.29.1 google-cloud -speech==0.36.3 googleapis-common-protos==1.6.0b9
  • 我很想使用 python3,但我有其他只适用于 python2.7 的库,我不想进行系统调用,但在 python 中拥有一切......

标签: python python-2.7 google-cloud-speech


【解决方案1】:

您遇到了包名之间的冲突。当您安装了google package 时,您的环境正试图从它而不是从google-api-core 获取api_core.protobuf_helpers 模块。

要解决此问题,请采用this answer 的方法。卸载google 包并使用不同的名称重新安装它。

另请注意,您使用的是 beta pre-releasegoogleapis-common-protos python. library。如果你想使用当前的稳定版本运行:

pip2 uninstall googleapis-common-protos
pip2 install googleapis-common-protos==1.5.8

【讨论】:

    【解决方案2】:

    谢谢大家!我按照建议卸载了所有 google python 模块。我按以下顺序重新安装了它们。 我遵循的顺序是:

    sudo pip2 install google 
    sudo pip2 install google-api-core 
    sudo pip2 install google-auth 
    sudo pip2 install google-cloud-core 
    sudo pip2 install google-cloud-speech 
    sudo pip2 install googleapis-common-protos
    

    现在可以了: {

    python2.7 interpreter.py multi-language
    Waiting for operation to complete...
    --------------------
    First alternative of result 0: transcript: "hello how are you"
    confidence: 0.984296917915
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-16
      • 2019-08-20
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 2019-03-28
      • 1970-01-01
      相关资源
      最近更新 更多