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.


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 .

链接地址: http://www.djcxy.com/p/12632.html

上一篇: Scala中的有效标识符字符

下一篇: 在python中使用谷歌的protobuf而不安装它