7

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

I tried this put could not figure out how. Could you give me some pointers as to what to do with the zip and egg file please. Just putting them on the PythonPath doesn't seem to do the trick.
@Cornelius: I was in the process of updating; a build is enough, really.
Ah, yes, I that was my first guess but if I do this I get the error message: "ImportError: No module named pkg_resources". Supposedly because I haven't got setuptools installed. Is this what you mean by command-line tool?
@Cornelius: No, pkg_resources is part of the setuptools distribution yes. I guess you'd have to include that too in your packaging. Why not just use the setuptools infrastructure instead and have pip or easy_install handle installation and dependencies for you?
Yes, you have to add the pkg_resources.py to you path as well for this to work. I found this answer also here: stackoverflow.com/questions/1252910/…. Could you update your answer please and then I'll check it as the correct one. Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.