Tensorflow TypeError:描述符不能直接创建



我已经在安装和设置GPU版本的tensorflow大约8个小时了。我终于把所有的东西都安装好了,但是当我试着测试它时,我得到了这个错误:

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
>>> import tensorflow as tf                                                                                                                                                                         
Traceback (most recent call last):              
File "<stdin>", line 1, in <module>
File "C:UsersAdminAppDataLocalProgramsPythonPython38libsite-packagestensorflow__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:UsersAdminAppDataLocalProgramsPythonPython38libsite-packagestensorflowpython__init__.py", line 40, in <module>
from tensorflow.python.eager import context
File "C:UsersAdminAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythoneagercontext.py", line 32, in <module>
from tensorflow.core.framework import function_pb2
File "C:UsersAdminAppDataLocalProgramsPythonPython38libsite-packagestensorflowcoreframeworkfunction_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "C:UsersAdminAppDataLocalProgramsPythonPython38libsite-packagestensorflowcoreframeworkattr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "C:UsersAdminAppDataLocalProgramsPythonPython38libsite-packagestensorflowcoreframeworktensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "C:UsersAdminAppDataLocalProgramsPythonPython38libsite-packagestensorflowcoreframeworkresource_handle_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "C:UsersAdminAppDataLocalProgramsPythonPython38libsite-packagestensorflowcoreframeworktensor_shape_pb2.py", line 36, in <module>
_descriptor.FieldDescriptor(
File "C:UsersAdminAppDataLocalProgramsPythonPython38libsite-packagesgoogleprotobufdescriptor.py", line 560, in __new__
return _message.default_pool.FindFieldByName(full_name)
TypeError: Descriptors cannot not 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

我将把我的安装设置放在下面供参考:

  • Tensorflow tripwire
  • Python 3.8.10
  • CUDA 10.1
  • cuDNN 7.6
  • 操作系统:Windows 10

通过将protobuf4.21.1版本降级到3.19.4版本,我解决了在导入tensorflow模块时面临的类似问题

$ pip install protobuf
Requirement already satisfied ... (4.21.1)
$ pip uninstall protobuf
Found existing installation: protobuf 4.21.1
Uninstalling protobuf-4.21.1:
Would remove:
/home/kali/.local/lib/python3.10/site-packages/google/protobuf/*
/home/kali/.local/lib/python3.10/site-packages/protobuf-4.21.1-py3.10-nspkg.pth
/home/kali/.local/lib/python3.10/site-packages/protobuf-4.21.1.dist-info/*
Proceed (Y/n)? Y
Successfully uninstalled protobuf-4.21.1
$ pip install protobuf==3.19.4

相关内容

  • 没有找到相关文章

最新更新