onnx: Import error with onnx-1.7.0 in mac os catalina

Hi I get the following error when I import onnx (python 3.7.7)

[libprotobuf ERROR google/protobuf/descriptor_database.cc:394] Invalid file descriptor data passed to EncodedDescriptorDatabase::Add().
[libprotobuf FATAL google/protobuf/descriptor.cc:1356] CHECK failed: GeneratedDatabase()->Add(encoded_file_descriptor, size): 
libc++abi.dylib: terminating with uncaught exception of type google::protobuf::FatalException: CHECK failed: GeneratedDatabase()->Add(encoded_file_descriptor, size): 

with onnx-1.6.0 no import errors

I tried changing version of protobuf using either

pip install protobuf==3.8.0 
pip install protobuf==3.12.2

and brew reinstall protobuf didn’t help Any Ideas? I have been trinying to fix this all day

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 24 (13 by maintainers)

Most upvoted comments

I’ve also faced this problem on my mac with onnx==1.7.0, protobuf==3.12.2, Python 3.7.7 on Max OSX Catalina 10.15.5.

It went away when I downgraded to onnx==1.6.0, not sure why.

Thank you for providing the info. I can repro this now. There are 3 possible ways to workaround this:

  1. Like you mentioned, downgrade the protobuf version.
  2. Use ONNX 1.6.0.
  3. import onnx before import tensorflow

I have 2 questions:

  1. How could you use protobuf==3.4.0 with the latest tensorflow? (I saw it has a requirement: tensorflow 2.4.0 requires protobuf>=3.9.2)
  2. I thought it only happens when import tensorflow first then import onnx. Did you encounter this error in other scenarios?

Thank you for bringing this up again to remind that this issue is still not resolved.

I finally got it to work! For one reason or another, everything works fine in a conda environment (I was using a Virtualenv environment before).

If installed in this order:

conda create --name myenv python=3.8

conda activate myenv

conda install -c conda-forge onnx

pip install tensorflow==2.2.1

everything works as it should.

Hi @jcwchen,

  1. Protobuf ==3.4.0 is only used to compile and install ONNX, and then when I install TensorFlow, pip will install a newer version of protobuf such as 3.14.0, to be compatible with TensorFlow. That’s why I emphasised here the order of installation is important.
  2. I think that’s my case as well, importing TensorFlow and then ONNX will cause the error.

Thanks