Importing tensorflow fails with Descriptors should not be created directly

Viewed 887

I used conda-forge to install tensorflow, but a simple import tensorflow fails with the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yonatan/anaconda3/envs/yonatan_env/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/home/yonatan/anaconda3/envs/yonatan_env/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 53, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/home/yonatan/anaconda3/envs/yonatan_env/lib/python3.8/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/yonatan/anaconda3/envs/yonatan_env/lib/python3.8/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/yonatan/anaconda3/envs/yonatan_env/lib/python3.8/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/yonatan/anaconda3/envs/yonatan_env/lib/python3.8/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/yonatan/anaconda3/envs/yonatan_env/lib/python3.8/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/yonatan/anaconda3/envs/yonatan_env/lib/python3.8/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 36, in <module>
    _descriptor.FieldDescriptor(
  File "/home/yonatan/.local/lib/python3.8/site-packages/google/protobuf/descriptor.py", line 530, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors should not be created directly, but only retrieved from their parent.

I use python 3.8.5, on my Ubuntu 18.04. I have tried changing the file name to have suffix _pb2 as I saw recommended, but the problem persisted. Has anyone encountered this?

0 Answers
Related