tensorflow / models

Models and examples built with TensorFlow
Other
76.78k stars 45.85k forks source link

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

Closed bilibilikanpei closed 2 months ago

bilibilikanpei commented 2 months ago

Prerequisites

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

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_attrvalue__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_tensorpb2 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_resourcehandlepb2 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_tensorshapepb2 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?

bilibilikanpei commented 2 months ago

f*ck, this is a fool issue. this condition is same with "ImportError: cannot import name 'builder' from 'google.protobuf.internal'".

I've just noticed that object_detection packages are not downloaded over the web, but rather parts of the code are generated locally and then built. By searching globally for problematic import statements, I noticed that they were all on the new green file, so the problem could be in the local generation step. The highest version of protobuf I initially installed, version 27, worked fine in version 3.18.1 after repeated degradation tests. Finally, you can pass the test

This should be added to note

image

zzanyoung commented 1 month ago

Excuse me, can you tell me a little more about how you solved it?

geoalex91 commented 1 month ago

Hi, how did you solve this issue?

zzanyoung commented 1 month ago

@geoalex91

This is the environment I set up for learning. It may be helpful for you to refer to it. I installed protobuf version 3.19.6in a new virtual environment and set the path to Protocol Buffers 22.0.​​​​​​​​​​​​​​​​

caoduythanh1997 commented 1 month ago

Can you tell me how to solve it?

zzanyoung commented 2 weeks ago

@caoduythanh1997 After installing Protocol Buffer version 22.0, follow the solution with the most votes at the address below. https://stackoverflow.com/questions/71759248/importerror-cannot-import-name-builder-from-google-protobuf-internal