Protocol Buffers with Python (I'm a noob)

409 views
Skip to first unread message

steph

unread,
Sep 20, 2012, 4:07:49 PM9/20/12
to prot...@googlegroups.com
I have been using protocol buffers with Cpp and Java and have gotten those running smoothly but I'm having trouble with python (admittedly I'm not very good with python so hopefully this isn't just me goofing something).

I have the main protocol buffer files, the source, protoc, protogen, all in one central location so that my build processes from Java and cpp can utilize the same files. Then in my java project I include proto2javame.jar and in cpp I include Google.Protocolbuffers.dll and that allows me to use the generated classes. However I can't find an equivalent for python. I have generated my python libraries but when I try to use them I get errors that No Module named google.protobuff exist (i'm using python 3.2.3).

How do I have my python generated classes import the appropriate libraries while still keeping all of my protobuff binaries in a central location? Is there a way to modify my build argument to include all necessary libraries.

My current build line looks like
%1 is the current protocol buffer file
>protoc --descriptor_set_out = %1.bin --proto_path=[mycomputerpath]\protos --proto_path=. --include_imports --python_out=. %1.proto

thanks!

Alex Roper

unread,
Sep 21, 2012, 9:29:00 AM9/21/12
to prot...@googlegroups.com
That should generate one or more files of the form package_pb2.py in the directory you ran protoc in. You can then import these into your program with:

import package_pb2

where package is the PB package you want.

steph

unread,
Sep 21, 2012, 9:44:21 AM9/21/12
to prot...@googlegroups.com
I'm able to import the generated protobuf files using import classa_pb2.py but the problem is when I then attempt to use classa_pb2 it throws errors before inside classa_pb2.py it it throws an ImportError: No Module name google.protobuf on the line "from google.protobuf import descriptor"

Alex Roper

unread,
Sep 22, 2012, 9:53:42 AM9/22/12
to prot...@googlegroups.com
When I've gotten this in the past it has been because either the protobuf libraries or the python bindings to them were not properly installed or were from different versions.
Reply all
Reply to author
Forward
0 new messages