google.protobuf installed, but module not found

2019-05-21 18:59发布

I have installed protobuf but when I run my script that uses pb.py it complains:

from google.protobuf import descriptor as _descriptor
    ImportError: No module named google.protobuf

However when I run protoc --version I see libprotoc 2.6.1 The previous posts say to see if protobuf is within the path of python, I can't find the protobuf path though.
Can anyone tell me what I'm doing wrong? I'm running Yosemite.

2条回答
劳资没心,怎么记你
2楼-- · 2019-05-21 19:33

I had that exact problem yesterday. Basically you have protoc already, you just need to let Python see it. Here's how to do it:
In your terminal: export PROTOC_PATH = 'which protoc' and then echo $PROTOC_PATH and then add PROTOC_PATH to your .bash_profile.

Hope that helps!

Emotional °昔
3楼-- · 2019-05-21 19:56

Be careful how the quotes are rendered, they should be BACKquotes:

export PROTOC_PATH=`which protoc`
登录 后发表回答