1

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
  • 1
    "cannot find a module"? Please post the full error. Commented Oct 25, 2016 at 14:30

1 Answer 1

3

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.

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

Comments

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.