[protobuf] Using Python protobuf library without setuptools?

269 views
Skip to first unread message

Nick Carter

unread,
Apr 8, 2010, 3:22:00 PM4/8/10
to prot...@googlegroups.com
My project pulls the protobuf source directly from code.google.com, and builds the tools and libs (protoc, libprotobuf, libprotobuf-lite) as part of its build process.  But now I want to use protos from Python, and I'm having trouble getting the python protobuf library to import properly from the generated _pb2.py code.

Protobuf's python/ directory is in my PYTHONPATH, but my standalone python build chokes on the python/google/__init__.py:

__import__('pkg_resources').declare_namespace(__name__)

because the hermetic python used by my build doesn't have setuptools.  Simply removing that line (or adding a try/except for ImportError) seems to make things to work for me.

Do I really need to pull in setuptools, in order to use python protobufs?  Or is there a way to make the pkgresources dependency optional?

 - nick

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.

Kenton Varda

unread,
Apr 8, 2010, 5:25:59 PM4/8/10
to Nick Carter, prot...@googlegroups.com
The purpose of that line is to declare that the "google" package is just a namespace, so that other google projects (like AppEngine) can also place their code under "google".  In retrospect, we probably should have just created a top-level "protobuf" package.

If you make sure that all packages that you are using under "google" are part of one big source tree, then the line is unnecessary -- it is only needed when the "google" package might appear in multiple locations in your python path.  So if this is the case for you, you can simply replace that __init__.py with an empty file.
Reply all
Reply to author
Forward
0 new messages