Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using google's protobuf in python without installing it

It seems to me that when I'm using protobuf in python I need to install it first so that I also have setuptools installed. To me it seems like this is severly limiting portability as I would have to install protobuf on every machine on which I want to use any kind of python code using protobuf.

So my question is: Is there a way to package protobuf for python in such a way, that it can be distributed with the python code using it?

Any info on this would be appreciated.

like image 438
Cornelius Avatar asked Mar 28 '13 13:03

Cornelius


People also ask

Is Google Protobuf open source?

Protocol Buffers (Protobuf) is a free and open-source cross-platform data format used to serialize structured data.


1 Answers

The package contains an experimental C++ extension, and the setup file generates Python files, but with the extension disabled by default, you should be able to include the setup.py build result with your script just fine.

Note that the Python package still needs the command-line tool to be installed. The tool is used to generate some Python for you.

Once that is available, run:

cd python
python setup.py build

and copy the build/lib/google directory to your script distribution, it needs to be on your sys.path to be importable.

Alternatively, use setup.py bdist --formats=zip and add the path to the resulting zipfile (located in dist/protobuf-<version>.<platform>-<architecture>.zip) to your sys.path. Renaming it should be fine.

Do note that the package uses a namespace, and thus the pkg_resources module needs to be available as well. It is only used to declare the google namespace in google/__init__.py.

like image 144
Martijn Pieters Avatar answered Nov 15 '22 10:11

Martijn Pieters