How to handle different versions of python protobuf

My python package contains a lot of files compiled by python-protobuf (python2-protobuf-2.5.0 on Arch Linux), I installed the package on a Ubuntu server 12.04.3 (which has python-protobuf-2.4.1), tried to run the code and click the following error:

from google.protobuf.internal import enum_type_wrapper
ImportError: cannot import name enum_type_wrapper

I think because the protobuf modules in my package compiled protobuf-2.5.0 and they do not work with protobuf-2.4.1.

I have no idea about the environments in which my code can work, the protobuf version may be different. How to make my package work with both protobuf 2.4 and 2.5?

(Possible way: include in my package two different sets of protobuf libraries (one compiled in 2.4.1, the other compiled in 2.5.0), get google.protobuf version at runtime and select protobuf libraries to import. Is it possible ?

+4
source share
2 answers

You need to specify the protobuf version that will work with yours setup.pyon the list install_requires=['protobuf>=2.5.0']. With the Python package, you can only put the name or exact versions that will be run along with the package using ==. I believe that you can also specify !=for certain versions.

setup.py, virtualenv install_requires.txt python .

:

$ cd ../project
$ virtualenv project_venv
$ source project_venv/bin/activate
$ cd project
$ pip install protobuf>=2.5.0
$ pip freeze > ./requirements.txt

-, , virtualenv :

$ pip install -r requirements.txt

, virtualenv, . setup.py. , , sudo python setup.py install python setup.py install .

virtualenv :

$ deactivate
+3

protobuf , , . , .

- protoc , .

, - , protobuf.

0

All Articles