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

问题描述 投票:1回答:2

我正在尝试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 python-2.7 google-cloud-speech
2个回答
1
投票

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

要克服这个问题,请采取this answer的方法。卸载google软件包并使用其他名称重新安装。

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

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

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

}

© www.soinside.com 2019 - 2024. All rights reserved.