ImportError: cannot import name 'builder' from 'google.protobuf.internal'

When i tested the file

python object_detection/builders/model_builder_tf2_test.py

, i encountered the following error.

Traceback (most recent call last):
  File "C:\Users\yunpeng\models\research\object_detection\builders\model_builder_tf2_test.py", line 24, in <module>
    from object_detection.builders import model_builder
  File "C:\Users\yunpeng\anaconda3\envs\tf2\lib\site-packages\object_detection\builders\model_builder.py", line 23, in <module>
    from object_detection.builders import anchor_generator_builder
  File "C:\Users\yunpeng\anaconda3\envs\tf2\lib\site-packages\object_detection\builders\anchor_generator_builder.py", line 26, in <module>
    from object_detection.protos import anchor_generator_pb2
  File "C:\Users\yunpeng\anaconda3\envs\tf2\lib\site-packages\object_detection\protos\anchor_generator_pb2.py", line 5, in <module>
    from google.protobuf.internal import builder as _builder
ImportError: cannot import name 'builder' from 'google.protobuf.internal' (C:\Users\yunpeng\anaconda3\envs\tf2\lib\site-packages\google\protobuf\internal\__init__.py)

How should you resolve this error?

@yunpeng_huo,

Could you please upgrade the protobuf package as shown below and let us know?

pip install --upgrade protobuf

Thank you!

thanks,i have solved it

there is same error in tensorflow exam, but they told us to install protobuf==3.19.6 only, if I update the protobuf, another error arises

@hamed2020,

Welcome to the Tensorflow Forum,

I would appreciate if you could open a new issue with standalone code and a stack trace so that it is easy to track and assist you quickly.

Thank you!

I have the same error. But when I upgrade the protobuf, I have this message>

Requirement already satisfied: protobuf in c:\users\alvaro felipe\desktop\tensorflow object detection\tfodcourse\tfod\lib\site-packages (3.19.4)
Collecting protobuf
Obtaining dependency information for protobuf from https://files.pythonhosted.org/packages/61/70/ee9585603255156d88f07528a6094733e37f8e3f72711b8583fcbb77d5ec/protobuf-4.24.4-cp37-cp37m-win_amd64.whl.metadata
Using cached protobuf-4.24.4-cp37-cp37m-win_amd64.whl.metadata (540 bytes)
Using cached protobuf-4.24.4-cp37-cp37m-win_amd64.whl (430 kB)
Installing collected packages: protobuf
Attempting uninstall: protobuf
Found existing installation: protobuf 3.19.4
Uninstalling protobuf-3.19.4:
Successfully uninstalled protobuf-3.19.4
Successfully installed protobuf-4.24.4
ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
apache-beam 2.48.0 requires protobuf<4.24.0,>=3.20.3, but you have protobuf 4.24.4 which is incompatible.
tensorboard 2.11.2 requires protobuf<4,>=3.9.2, but you have protobuf 4.24.4 which is incompatible.
tensorflow-intel 2.11.0 requires protobuf<3.20,>=3.9.2, but you have protobuf 4.24.4 which is incompatible.