Import tensorflow now broken, TypeError: __new__() got an unexpected keyword argument 'serialized_options'

Hi everyone,
I am using tensorflow-gpu==2.6.0
I broke something, have tried to reinstall both tensorflow-gpu==2.6.0 and numpy because an error message suggested that I do so.

How do I fix the following? Previously, importing tensorflow woild result in a notification about using CUDA etc.

I have tried upgrading protobuf through pip, but that has not worked either.

Please help, thanks in advance!

chaztikov@liberty:~$ python3
Python 3.6.9 (default, Mar 15 2022, 13:55:28)
[GCC 8.4.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import tensorflow as tf
Traceback (most recent call last):
File “”, line 1, in
File “/home/chaztikov/.local/lib/python3.6/site-packages/tensorflow/init.py”, line 41, in
from tensorflow.python.tools import module_util as _module_util
File “/home/chaztikov/.local/lib/python3.6/site-packages/tensorflow/python/init.py”, line 40, in
from tensorflow.python.eager import context
File “/home/chaztikov/.local/lib/python3.6/site-packages/tensorflow/python/eager/context.py”, line 32, in
from tensorflow.core.framework import function_pb2
File “/home/chaztikov/.local/lib/python3.6/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 “/home/chaztikov/.local/lib/python3.6/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 “/home/chaztikov/.local/lib/python3.6/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 “/home/chaztikov/.local/lib/python3.6/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 “/home/chaztikov/.local/lib/python3.6/site-packages/tensorflow/core/framework/tensor_shape_pb2.py”, line 23, in
serialized_pb=_b(’\n,tensorflow/core/framework/tensor_shape.proto\x12\ntensorflow"z\n\x10TensorShapeProto\x12-\n\x03\x64im\x18\x02 \x03(\x0b\x32 .tensorflow.TensorShapeProto.Dim\x12\x14\n\x0cunknown_rank\x18\x03 \x01(\x08\x1a!\n\x03\x44im\x12\x0c\n\x04size\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\tB\x87\x01\n\x18org.tensorflow.frameworkB\x11TensorShapeProtosP\x01ZSgithub.com/tensorflow/tensorflow/tensorflow/go/core/framework/tensor_shape_go_proto\xf8\x01\x01\x62\x06proto3’)
TypeError: new() got an unexpected keyword argument ‘serialized_options’

I accidentally pip3 installed something (forget what) that caused an update

1 Like

Please try again using pip3 install -U protobuf. Let us know if the issue still persists. Thank you.

1 Like

You may have accidentally touched the source code for tensorflow and corrupted it. To fix this, you need to go into the cached tensorflow which is stored in ~/.local/lib/python3.x/site-packages and remove all tensorflow* and tensorboard*. Then do pip install tensorflow again, and it should force a reinstall.

The error message “TypeError: new() got an unexpected keyword argument ‘serialized_options’” typically occurs in TensorFlow when there is a mismatch between the version of TensorFlow being used and the code or environment in which it is being executed. This error is related to the serialization and deserialization of options in TensorFlow.

To resolve this issue, you can try the following steps:

  1. Check TensorFlow Version: Ensure that you are using the latest version of TensorFlow that is compatible with your code and environment. You can check the version of TensorFlow installed by running the following command in Python:

pythonCopy code

import tensorflow as tf
print(tf.__version__)

If you are using an older version of TensorFlow, you may need to upgrade to a newer version that supports the ‘serialized_options’ argument.

  1. Update Code: If you have recently upgraded TensorFlow or are using code from a different source, make sure that your code is compatible with the version of TensorFlow being used. Some code snippets or examples may be outdated and not compatible with the latest version of TensorFlow.
  2. Check Environment: Ensure that your Python environment and dependencies are properly set up. Make sure that you have installed all the necessary dependencies and that there are no conflicts between different packages or libraries.
  3. Check Serialized Options: If you are using serialized options explicitly in your code, double-check that they are being used correctly. The ‘serialized_options’ argument may not be supported in certain contexts or may require specific usage.
  4. Report Bug: If you are using the latest version of TensorFlow and are still facing the issue, it may be a bug. In that case, you can report the issue to the TensorFlow GitHub repository or the TensorFlow community forums for further assistance.

By following these steps, you should be able to resolve the “TypeError: new() got an unexpected keyword argument ‘serialized_options’” error in TensorFlow.