Using google protobuf in python without installing it

It seems to me that when I use protobuf in python, I need to install it first so that I also have setuptools installed. For me, it looks like it severely limits portability, since I will need to install protobuf on every machine on which I want to use any python code using protobuf.

So my question is: is there a way to package protobuf for python so that it can be distributed using python code using it?

Any information on this would be appreciated.

+7
source share
1 answer

The package contains the experimental C ++ extension, and the installation file generates Python files, but the extension is disabled by default, you can simply add the result of setup.py build with your script.

Note that the Python package still needs a command line tool for installation. The tool is used to create some Python for you.

Once this is available, run:

 cd python python setup.py build 

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

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

Note that the package uses a namespace, and therefore the pkg_resources module pkg_resources also be available. It is used only to declare the google namespace in google/__init__.py .

+3
source

All Articles