简体   繁体   English

在python中使用google的protobuf而不安装它

[英]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. 在我看来,当我在python中使用protobuf时,我需要先安装它,以便我也安装了setuptools。 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. 对我来说,似乎这是严重限制可移植性,因为我必须在每台机器上安装protobuf,我想使用protobuf使用任何类型的python代码。

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? 所以我的问题是:有没有办法以这种方式为python包装protobuf,它可以使用python代码分发它?

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. 该软件包包含一个实验性的C ++扩展,并且安装文件生成Python文件,但默认情况下禁用扩展,您应该能够在脚本中包含setup.py build结果。

Note that the Python package still needs the command-line tool to be installed. 请注意,Python包仍然需要安装命令行工具。 The tool is used to generate some Python for you. 该工具用于为您生成一些Python。

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. 并将build/lib/google目录复制到您的脚本分发中,它需要在您的sys.path上才能导入。

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 . 或者,使用setup.py bdist --formats=zip并将生成的setup.py bdist --formats=zip (位于dist/protobuf-<version>.<platform>-<architecture>.zip )的路径添加到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. 请注意,程序包使用命名空间,因此pkg_resources模块也需要可用。 It is only used to declare the google namespace in google/__init__.py . 它仅用于在google/__init__.py声明google名称空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM