I encountered it while executing from object_detection.utils import label_map_util
in jupyter notebook. It is actually the tensorflow object detection tutorial
The below three commands solved it for me:
pip uninstall protobuf python3-protobuf
pip install --upgrade pip
pip install --upgrade protobuf
Hope this helps.
After trying many different solutions (i'm working on a Mac) the one that worked for me is to reinstall protobuf using:
PROTOC_ZIP=protoc-3.7.1-osx-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP
As is highlighted in this article
This is a solution which worked for me I'm not sure if it'll work for others.
The protoc verion I got through pip show protobuf
and protoc --version
were different. The version in pip was a bit outdated after I upgraded the pip version the problem was solved.
In order to upgrade it use pip install --upgrade protobuf
For others looking into this more recently newer google libraries are using proto plus, a wrapper for python proto messages. Using this helper function worked for me (cred: tobked)
import json
import proto
def proto_message_to_dict(message: proto.Message) -> dict:
"""Helper method to parse protobuf message to dictionary."""
return json.loads(message.__class__.to_json(message))
https://github.com/googleapis/python-memcache/issues/19