没有名为api_core.protobuf_helpers的模块。 python2.7和googlecloud

时间:2019-03-13 13:22:46

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

我正在尝试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

2 个答案:

答案 0 :(得分:1)

您在软件包名称之间遇到冲突。安装了google package后,您的环境正在尝试从中而不是从api_core.protobuf_helpers来获取google-api-core模块。

要解决此问题,请采用this answer的方法。卸载google软件包,然后使用其他名称重新安装。

还要注意,您使用的是beta pre-release中的googleapis-common-protos python. library。如果要使用当前的稳定版本,请运行:

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

答案 1 :(得分:0)

谢谢大家!我遵循了建议,并卸载了所有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

}