Skip to content

cannot import name 'runtime_version' from 'google.protobuf'  #11192

@bilibilikanpei

Description

@bilibilikanpei

Prerequisites

Please answer the following question for yourself before submitting an issue.

  • I checked to make sure that this issue has not been filed already.

1. The entire URL of the documentation with the issue

https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2.md

2. Describe the issue

windows10
python 3.8.6 and 3.9.13

I followed the steps above
An error occurred in this step
python object_detection/builders/model_builder_tf2_test.py

PS C:\Users\abc\Desktop\third\models\research> python object_detection/builders/model_builder_tf2_test.py
2024-04-20 15:35:17.379356: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2024-04-20 15:35:17.379541: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
File "object_detection/builders/model_builder_tf2_test.py", line 24, in
from object_detection.builders import model_builder
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\object_detection\builders\model_builder.py", line 23, in
from object_detection.builders import anchor_generator_builder
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\object_detection\builders\anchor_generator_builder.py", line 26, in
from object_detection.protos import anchor_generator_pb2
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\object_detection\protos\anchor_generator_pb2.py", line 9, in
from google.protobuf import runtime_version as runtime_version
ImportError: cannot import name 'runtime_version' from 'google.protobuf' (C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\google\protobuf_init
.py)

so i upgrade protobuf, but

PS C:\Users\abc\Desktop\third\models\research> pip install --upgrade protobuf
Requirement already satisfied: protobuf in c:\users\abc\appdata\local\programs\python\python38\lib\site-packages (3.19.6)
Collecting protobuf
Using cached protobuf-5.26.1-cp38-cp38-win_amd64.whl.metadata (592 bytes)
Using cached protobuf-5.26.1-cp38-cp38-win_amd64.whl (420 kB)
Installing collected packages: protobuf
Attempting uninstall: protobuf
Found existing installation: protobuf 3.19.6
Uninstalling protobuf-3.19.6:
Successfully uninstalled protobuf-3.19.6
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.46.0 requires protobuf<4,>3.12.2, but you have protobuf 5.26.1 which is incompatible.
google-api-core 2.18.0 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0.dev0,>=3.19.5, but you have protobuf 5.26.1 which is incompatible.
googleapis-common-protos 1.63.0 requires protobuf!=3.20.0,!=3.20.1,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0.dev0,>=3.19.5, but you have protobuf 5.26.1 which is incompatible.
proto-plus 1.23.0 requires protobuf<5.0.0dev,>=3.19.0, but you have protobuf 5.26.1 which is incompatible.
tensorboard 2.10.1 requires protobuf<3.20,>=3.9.2, but you have protobuf 5.26.1 which is incompatible.
tensorflow 2.10.1 requires protobuf<3.20,>=3.9.2, but you have protobuf 5.26.1 which is incompatible.
tensorflow-intel 2.13.0 requires keras<2.14,>=2.13.1, but you have keras 2.10.0 which is incompatible.
tensorflow-intel 2.13.0 requires protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3, but you have protobuf 5.26.1 which is incompatible.
tensorflow-intel 2.13.0 requires tensorboard<2.14,>=2.13, but you have tensorboard 2.10.1 which is incompatible.
tensorflow-intel 2.13.0 requires tensorflow-estimator<2.14,>=2.13.0, but you have tensorflow-estimator 2.10.0 which is incompatible.
tensorflow-metadata 1.13.0 requires protobuf<4,>=3.13, but you have protobuf 5.26.1 which is incompatible.
Successfully installed protobuf-5.26.1

and retry

PS C:\Users\abc\Desktop\third\models\research> python object_detection/builders/model_builder_tf2_test.py
2024-04-20 15:39:40.849296: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2024-04-20 15:39:40.849483: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
File "object_detection/builders/model_builder_tf2_test.py", line 21, in
import tensorflow.compat.v1 as tf
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_init_.py", line 37, in
from tensorflow.python.tools import module_util as module_util
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python_init
.py", line 37, in
from tensorflow.python.eager import context
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\context.py", line 29, in
from tensorflow.core.framework import function_pb2
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\core\framework\function_pb2.py", line 16, in
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\core\framework\attr_value_pb2.py", line 16, in
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\core\framework\tensor_pb2.py", line 16, in
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\core\framework\resource_handle_pb2.py", line 16, in
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\core\framework\tensor_shape_pb2.py", line 36, in
_descriptor.FieldDescriptor(
File "C:\Users\abc\AppData\Local\Programs\Python\Python38\lib\site-packages\google\protobuf\descriptor.py", line 621, in new
_message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:

  1. Downgrade the protobuf package to 3.20.x or lower.
  2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

how to fix this?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions