我已經在Python 3.4中安裝了protobuf,並且我將已編譯的代碼pb_x_pb2.py
推送到python34文件夾中。當我輸入import pb_x_pb2.py
時,它顯示以下錯誤。我們如何在Python代碼中使用Python生成的protobuf代碼?
>>> import pb_interface_pb2
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
import pb_interface_pb2
File "C:\Python34\pb_interface_pb2.py", line 5, in <module>
from google.protobuf import reflection
File "C:\Python34\lib\site-packages\google\protobuf\reflection.py", line 68, in <module>
from google.protobuf.internal import python_message
File "C:\Python34\lib\site-packages\google\protobuf\internal\python_message.py", line 848
except struct.error, e:
^
SyntaxError: invalid syntax
你爲Python 3編譯過嗎?語法看起來像Python 2. – 2015-04-01 11:40:56
哦!這意味着我只能使用Python 2.7? – raghu 2015-04-01 11:44:56
Protobuffer應該在3.x下支持。但是,如果您爲Python 2.x編譯,結果將僅在2.x下運行。你是如何將Protobuffer文件編譯爲Python的? – 2015-04-01 11:46:26