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.
Protocol Buffers (Protobuf) is a free and open-source cross-platform data format used to serialize structured data.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With