【发布时间】: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