我正在尝试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_helperspip2 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发布于 2019-03-14 21:17:33
程序包名称之间存在冲突。安装了google package后,您的环境将尝试从它而不是从google-api-core获取api_core.protobuf_helpers模块。
要解决这个问题,可以采用this answer的方法。卸载google软件包,然后使用不同的名称重新安装。
还要注意,您使用的是googleapis-common-protos python. library的beta pre-release。如果您想使用当前的稳定版本,请运行:
pip2 uninstall googleapis-common-protos
pip2 install googleapis-common-protos==1.5.8发布于 2019-03-15 00:23:27
谢谢大家!我按照建议卸载了所有的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}
https://stackoverflow.com/questions/55142941
复制相似问题