I'm using a Mac/Linux and I'm trying to get python code generated from a .proto file. When I run the protoc --version
command in my terminal it returns libprotoc 22.5
.
When I run a terminal command like
protoc --python_out=. ./path/to/my/proto_file.proto
.
I get a python file that auto generates and the first line of the file is
from google.protobuf.internal import builder as _builder
When I try to run that line in my current python environment, I get this error.
Traceback (most recent call last):
File "/Users/me/opt/miniconda3/envs/my_env/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3505, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-3-9454f45a4b99>", line 1, in <module>
from google.protobuf.internal import builder as _builder
ImportError: cannot import name 'builder' from 'google.protobuf.internal' (/Users/me/opt/miniconda3/envs/my_env/lib/python3.8/site-packages/google/protobuf/internal/__init__.py)
In this SO Question, and several other places, it recommends that you upgrade your version of protobuf to resolve the error. However, due to package dependencies, I can't update my protobuf package to anything over version 3.19.6. I'm assuming that I need to downgrade my protoc version on my mac to match the older python protobuf version so that the auto-generated code will only reference packages/methods/functions that exist in python version 3.19.6. What version should I downgrade protoc to, and how would I do that (I have homebrew installed and can use brew
commands)?