tensorflow/models

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

bilibilikanpei opened this issue ยท 21 comments

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?

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

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

Hi, how did you solve this issue?

@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.โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹

Can you tell me how to solve it?

@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

i tried copy pasting the builder.py but it is not helping for this ""cannot import name 'runtime_version' from 'google.protobuf' ""error please can someone help

@SanjayDurai Have you tried installing protocol buffer version v22 from the protocolbuffers/protobuf repository?

@SanjayDurai Have you tried installing protocol buffer version v22 from the protocolbuffers/protobuf repository?

just tried after you said but still same error
Traceback (most recent call last):
File "E:\PROJECTS\SignLanguageDetection\RealTimeObjectDetection\Tensorflow\scripts/generate_tfrecord.py", line 29, in
from object_detection.utils import dataset_util, label_map_util
File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\utils\label_map_util.py", line 29, in
from object_detection.protos import string_int_label_map_pb2
File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\protos\string_int_label_map_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\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf_init
.py)
Traceback (most recent call last):
File "E:\PROJECTS\SignLanguageDetection\RealTimeObjectDetection\Tensorflow\scripts/generate_tfrecord.py", line 29, in
from object_detection.utils import dataset_util, label_map_util
File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\utils\label_map_util.py", line 29, in
from object_detection.protos import string_int_label_map_pb2
File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\protos\string_int_label_map_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\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf_init
.py)

I'm using THIS Video for learning Object detection pls help I'm stuck at create TF records part

@SanjayDurai If that's the case, it's possible there might be an issue with the file paths or the input format. Unless you absolutely need to do the conversion locally, I recommend trying out Roboflow. It can easily generate tfrecords for you. Hope this helps

Thanks Bro ill try it

Thanks Bro ill try it

did it worked?

@SanjayDurai Have you tried installing protocol buffer version v22 from the protocolbuffers/protobuf repository?

just tried after you said but still same error Traceback (most recent call last): File "E:\PROJECTS\SignLanguageDetection\RealTimeObjectDetection\Tensorflow\scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\utils\label_map_util.py", line 29, in from object_detection.protos import string_int_label_map_pb2 File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\protos\string_int_label_map_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\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf__init_.py) Traceback (most recent call last): File "E:\PROJECTS\SignLanguageDetection\RealTimeObjectDetection\Tensorflow\scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\utils\label_map_util.py", line 29, in from object_detection.protos import string_int_label_map_pb2 File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\protos\string_int_label_map_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\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf__init_.py)

If anyone is still confused, the reason this error occurred is because runtime_version.py file cannot be found in C:\Users\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf directory. The workaround from this post was to:

  1. Update protobuf pip install --upgrade protobuf which generates the runtime_version.py
  2. Copy it somewhere else
  3. Downgrade back to compatible version pip install protobuf==3.19.6. Check compatible version in previous terminal message:
    Attempting uninstall: protobuf Found existing installation: protobuf 3.19.6 Uninstalling protobuf-3.19.6: Successfully uninstalled protobuf-3.19.6
  4. Downgrade removes the runtime_version.py file. Now, copy back the file.

Try running test again python object_detection/builders/model_builder_tf2_test.py. In my case I faced the similar issue, this time with \envs\tensorflow\lib\site-packages\google\protobuf\internal\builder.py. Just repeat the steps before with builder.py file.

@SanjayDurai Have you tried installing protocol buffer version v22 from the protocolbuffers/protobuf repository?

just tried after you said but still same error Traceback (most recent call last): File "E:\PROJECTS\SignLanguageDetection\RealTimeObjectDetection\Tensorflow\scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\utils\label_map_util.py", line 29, in from object_detection.protos import string_int_label_map_pb2 File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\protos\string_int_label_map_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\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf__init_.py) Traceback (most recent call last): File "E:\PROJECTS\SignLanguageDetection\RealTimeObjectDetection\Tensorflow\scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\utils\label_map_util.py", line 29, in from object_detection.protos import string_int_label_map_pb2 File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\protos\string_int_label_map_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\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf__init_.py)

If anyone is still confused, the reason this error occurred is because runtime_version.py file cannot be found in C:\Users\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf directory. The workaround from this post was to:

  1. Update protobuf pip install --upgrade protobuf which generates the runtime_version.py
  2. Copy it somewhere else
  3. Downgrade back to compatible version pip install protobuf==3.19.6. Check compatible version in previous terminal message:
    Attempting uninstall: protobuf Found existing installation: protobuf 3.19.6 Uninstalling protobuf-3.19.6: Successfully uninstalled protobuf-3.19.6
  4. Downgrade removes the runtime_version.py file. Now, copy back the file.

Try running test again python object_detection/builders/model_builder_tf2_test.py. In my case I faced the similar issue, this time with \envs\tensorflow\lib\site-packages\google\protobuf\internal\builder.py. Just repeat the steps before with builder.py file.

THANKYOU SO MUCH @namasSinjali IT WORKED FINALLY WITHOUT ANY ERRORS

ANYBODY OVER HERE COMPLETED THE SIGN LANGUAGE DETETCTION FROM HERE OR HAVE GOOD KNOWLEDGE ON OBJECT DETECTION PLS HELP ME I HAVE COMPLETED THE PROJECT BUT THE MODEL IS ALWAYS DETECTING "YES" AND NOTHING ELSE I TRIED TRAING FOR MORE STEPS BUT STILL ITS DETETCTING ONLY "YES" AND NOT OTHER CLASSES

3. pip install protobuf==3.19.6

wow this is worked for me. THANKS

@SanjayDurai Have you tried installing protocol buffer version v22 from the protocolbuffers/protobuf repository?

just tried after you said but still same error Traceback (most recent call last): File "E:\PROJECTS\SignLanguageDetection\RealTimeObjectDetection\Tensorflow\scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\utils\label_map_util.py", line 29, in from object_detection.protos import string_int_label_map_pb2 File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\protos\string_int_label_map_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\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf__init_.py) Traceback (most recent call last): File "E:\PROJECTS\SignLanguageDetection\RealTimeObjectDetection\Tensorflow\scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\utils\label_map_util.py", line 29, in from object_detection.protos import string_int_label_map_pb2 File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\protos\string_int_label_map_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\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf__init_.py)

If anyone is still confused, the reason this error occurred is because runtime_version.py file cannot be found in C:\Users\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf directory. The workaround from this post was to:

  1. Update protobuf pip install --upgrade protobuf which generates the runtime_version.py
  2. Copy it somewhere else
  3. Downgrade back to compatible version pip install protobuf==3.19.6. Check compatible version in previous terminal message:
    Attempting uninstall: protobuf Found existing installation: protobuf 3.19.6 Uninstalling protobuf-3.19.6: Successfully uninstalled protobuf-3.19.6
  4. Downgrade removes the runtime_version.py file. Now, copy back the file.

Try running test again python object_detection/builders/model_builder_tf2_test.py. In my case I faced the similar issue, this time with \envs\tensorflow\lib\site-packages\google\protobuf\internal\builder.py. Just repeat the steps before with builder.py file.

THANKYOU SO MUCH @namasSinjali IT WORKED FINALLY WITHOUT ANY ERRORS

hey bro where is the path of runtime_version.py can you please tell me

@SanjayDurai Have you tried installing protocol buffer version v22 from the protocolbuffers/protobuf repository?

just tried after you said but still same error Traceback (most recent call last): File "E:\PROJECTS\SignLanguageDetection\RealTimeObjectDetection\Tensorflow\scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\utils\label_map_util.py", line 29, in from object_detection.protos import string_int_label_map_pb2 File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\protos\string_int_label_map_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\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf__init_.py) Traceback (most recent call last): File "E:\PROJECTS\SignLanguageDetection\RealTimeObjectDetection\Tensorflow\scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\utils\label_map_util.py", line 29, in from object_detection.protos import string_int_label_map_pb2 File "C:\Users\SANJAY.conda\envs\py37\lib\site-packages\object_detection\protos\string_int_label_map_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\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf__init_.py)

If anyone is still confused, the reason this error occurred is because runtime_version.py file cannot be found in C:\Users\SANJAY.conda\envs\py37\lib\site-packages\google\protobuf directory. The workaround from this post was to:

  1. Update protobuf pip install --upgrade protobuf which generates the runtime_version.py
  2. Copy it somewhere else
  3. Downgrade back to compatible version pip install protobuf==3.19.6. Check compatible version in previous terminal message:
    Attempting uninstall: protobuf Found existing installation: protobuf 3.19.6 Uninstalling protobuf-3.19.6: Successfully uninstalled protobuf-3.19.6
  4. Downgrade removes the runtime_version.py file. Now, copy back the file.

Try running test again python object_detection/builders/model_builder_tf2_test.py. In my case I faced the similar issue, this time with \envs\tensorflow\lib\site-packages\google\protobuf\internal\builder.py. Just repeat the steps before with builder.py file.

THANKYOU SO MUCH @namasSinjali IT WORKED FINALLY WITHOUT ANY ERRORS

hey bro where is the path of runtime_version.py can you please tell me

.../Lib/site-packages/google/protobuf/internal

3. pip install protobuf==3.19.6

in my case i couldn't find runtime_version.py file but there is builder.py even if i followed all those steps still i am getting the same error. Can you please tell me how can i resolve that and btw do i need to restart my pc after copying builder.py ?

  1. pip install protobuf==3.19.6

in my case i couldn't find runtime_version.py file but there is builder.py even if i followed all those steps still i am getting the same error. Can you please tell me how can i resolve that and btw do i need to restart my pc after copying builder.py ?

You should find the file path information in error message.