我正在尝试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
您正在获得包名称之间的冲突。当你安装了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
感谢大家!我按照建议并卸载了所有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
}