当前位置:网站首页>Error encountered while importing keras typeerror: descriptors cannot not be created directly If this call came from a _

Error encountered while importing keras typeerror: descriptors cannot not be created directly If this call came from a _

2022-06-22 06:29:00 Work quietly

Problem description

The version corresponds to

keras And tensorflow Version correspondence :https://master–floydhub-docs.netlify.app/guides/environments/

The version of this paper is : tensorflow 2.2.0 + keras 2.3.0 + python3.7
The version correspondence must be consistent with the table description in the link , Otherwise, it is easy to report an error

The following instructions can be executed in sequence :
conda Revision in China python Version command :conda install python=3.7; Or create a new one conda Environmental Science conda create -n keras python=3.7, Choose one of the two commands to execute .
pip install keras==2.3.0
pip install tensorflow==2.2.0

Problem description

In execution import keras The following error occurred while executing the command :

(keras) [email protected]:~/xxxxxx/MatchZoo-master$ python
Python 3.7.13 (default, Mar 29 2022, 02:18:16) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using TensorFlow backend.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/keras/__init__.py", line 3, in <module>
    from . import utils
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/keras/utils/__init__.py", line 6, in <module>
    from . import conv_utils
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/keras/utils/conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/keras/backend/__init__.py", line 1, in <module>
    from .load_backend import epsilon
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/keras/backend/load_backend.py", line 90, in <module>
    from .tensorflow_backend import *
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/tensorflow/__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/tensorflow/python/__init__.py", line 53, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 16, in <module>
    from tensorflow.core.framework import function_pb2 as tensorflow_dot_core_dot_framework_dot_function__pb2
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/tensorflow/core/framework/function_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 "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
    from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/tensorflow/core/framework/tensor_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 "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/tensorflow/core/framework/resource_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 "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 42, in <module>
    serialized_options=None, file=DESCRIPTOR),
  File "/home/work/anaconda3/envs/keras/lib/python3.7/site-packages/google/protobuf/descriptor.py", line 560, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
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).

Problem solving

pip install protobuf~=3.19.0

Successful solution

Then execute again import keras No mistake :

(keras) [email protected]-cli0crch:~/xxxxxx/MatchZoo-master$ python
Python 3.7.13 (default, Mar 29 2022, 02:18:16) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using TensorFlow backend.
>>> import tensorflow
原网站

版权声明
本文为[Work quietly]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220622058318.html