我的Python包含许多由python-protobuf编译的文件(在Arch Linux上是python2-protobuf-2.5.0),我在Ubuntu服务器12.04.3上安装了该软件包(其中包含python-protobuf-2.4.1),尝试运行代码,结果出现以下错误:
from google.protobuf.internal import enum_type_wrapper
ImportError: cannot import name enum_type_wrapper
我认为问题出在我的软件包中的 protobuf 模块是由 protobuf-2.5.0 编译的,因此无法与 protobuf-2.4.1 兼容。
我不知道我的代码可能在哪些环境中运行,protobuf 的版本可能会有所不同。如何使我的软件包同时兼容 protobuf 2.4 和 2.5?
(一种可能的方法:在我的软件包中包含两个不同版本的 protobuf 库(一个由 2.4.1 编译,另一个由 2.5.0 编译),在运行时获取 google.protobuf 版本并选择要导入的 protobuf 库。这种方法可行吗?)