Tensorflow import error

I’ve had the same error when I attempt to import Tensorflow.

I fixed the error by installing all the packing again in a new environment. Try to install Tensorflow by using the command:- Conda install -c conda-forge Tensorflow

I tried that command and am still getting the same error.

Still getting an error message when attempting to import tensor flow. Suggestions?

TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_21392\4294963926.py in
----> 1 import tensorflow

~\AppData\Roaming\Python\Python39\site-packages\tensorflow_init_.py in
39 import sys as _sys
40
—> 41 from tensorflow.python.tools import module_util as _module_util
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
43

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python_init_.py in
38 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
39
—> 40 from tensorflow.python.eager import context
41 from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
42

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\eager\context.py in
30 import six
31
—> 32 from tensorflow.core.framework import function_pb2
33 from tensorflow.core.protobuf import config_pb2
34 from tensorflow.core.protobuf import rewriter_config_pb2

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\core\framework\function_pb2.py in
14
15
—> 16 from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
17 from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
18 from tensorflow.core.framework import op_def_pb2 as tensorflow_dot_core_dot_framework_dot_op__def__pb2

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\core\framework\attr_value_pb2.py in
14
15
—> 16 from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
17 from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
18 from tensorflow.core.framework import types_pb2 as tensorflow_dot_core_dot_framework_dot_types__pb2

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\core\framework\tensor_pb2.py in
14
15
—> 16 from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
17 from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
18 from tensorflow.core.framework import types_pb2 as tensorflow_dot_core_dot_framework_dot_types__pb2

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\core\framework\resource_handle_pb2.py in
14
15
—> 16 from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
17 from tensorflow.core.framework import types_pb2 as tensorflow_dot_core_dot_framework_dot_types__pb2
18

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\core\framework\tensor_shape_pb2.py in
34 containing_type=None,
35 fields=[
—> 36 _descriptor.FieldDescriptor(
37 name=‘size’, full_name=‘tensorflow.TensorShapeProto.Dim.size’, index=0,
38 number=1, type=3, cpp_type=2, label=1,

~\AppData\Roaming\Python\Python39\site-packages\google\protobuf\descriptor.py in new(cls, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options, serialized_options, has_default_value, containing_oneof, json_name, file, create_key)
558 has_default_value=True, containing_oneof=None, json_name=None,
559 file=None, create_key=None): # pylint: disable=redefined-builtin
→ 560 _message.Message._CheckCalledFromGeneratedFile()
561 if is_extension:
562 return _message.default_pool.FindExtensionByName(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: Changes made on May 6, 2022  |  Protocol Buffers  |  Google Developers