0
votes

My goal is to parse Protocol Buffers file with an extension filename.pb.string. Downloaded Protobuff using Homebrew on Mac. Ran protoc --version and have libprotoc 3.1.0 version.

But when I run Python it says cannot find a module. I changed my .pb file name to _pb2.py and import the module in my Python Script.

import filename_pb2 as proto

I am using Google Docs but still not having any luck. I am also having issues with compiling Protobuf .so files via Python. I am just not able to process how Protobuf and Python link together. Can someone please guide me?

Python Error

import response_123_pb2 as proto
ImportError: No module named response_123_pb2
1
"cannot find a module"? Please post the full error. - John Zwinck

1 Answers

2
votes

You have to compile your .proto file to a *_pb2.py file:

protoc --python_out=./ YourProto.proto

Make sure it produces a file named YourProto_pb2.py. Then you can import it to your code with:

import YourProto_pb2 as proto

If you are having other problems with the compile, then it is another matter. Be sure to check out this documentation.