Error building keras-2.7.0

I am running into the following error when building keras-2.7.0:

Traceback (most recent call last):
  File "/tmp/spackvixapidb/c19c5e115f6adb500190afacc8c6c4f6/execroot/org_keras/bazel-out/k8-opt-exec-2B5CBBC6/bin/keras/api/create_keras_api_1_keras_python_api_gen.runfiles/org_keras/keras/api/create_python_api_wrapper.py", line 26, in <module>
    import keras  # pylint: disable=unused-import
  File "/tmp/spackvixapidb/c19c5e115f6adb500190afacc8c6c4f6/execroot/org_keras/bazel-out/k8-opt-exec-2B5CBBC6/bin/keras/api/create_keras_api_1_keras_python_api_gen.runfiles/org_keras/keras/__init__.py", line 21, in <module>
    from tensorflow.python import tf2
  File "/opt/packages/gpjohnsn/prefix/opt/apps/x86_64/gcc-9.3.0/py-tensorflow-2.7.0-pfpeahr/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/opt/packages/gpjohnsn/prefix/opt/apps/x86_64/gcc-9.3.0/py-tensorflow-2.7.0-pfpeahr/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 41, in <module>
    from tensorflow.python.eager import context
  File "/opt/packages/gpjohnsn/prefix/opt/apps/x86_64/gcc-9.3.0/py-tensorflow-2.7.0-pfpeahr/lib/python3.8/site-packages/tensorflow/python/eager/context.py", line 33, in <module>
    from tensorflow.core.framework import function_pb2
  File "/opt/packages/gpjohnsn/prefix/opt/apps/x86_64/gcc-9.3.0/py-tensorflow-2.7.0-pfpeahr/lib/python3.8/site-packages/tensorflow/core/framework/function_pb2.py", line 14, in <module>
    from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
  File "/opt/packages/gpjohnsn/prefix/opt/apps/x86_64/gcc-9.3.0/py-tensorflow-2.7.0-pfpeahr/lib/python3.8/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 14, in <module>
    from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
  File "/opt/packages/gpjohnsn/prefix/opt/apps/x86_64/gcc-9.3.0/py-tensorflow-2.7.0-pfpeahr/lib/python3.8/site-packages/tensorflow/core/framework/tensor_pb2.py", line 14, in <module>
    from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
  File "/opt/packages/gpjohnsn/prefix/opt/apps/x86_64/gcc-9.3.0/py-tensorflow-2.7.0-pfpeahr/lib/python3.8/site-packages/tensorflow/core/framework/resource_handle_pb2.py", line 14, in <module>
    from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
  File "/opt/packages/gpjohnsn/prefix/opt/apps/x86_64/gcc-9.3.0/py-tensorflow-2.7.0-pfpeahr/lib/python3.8/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 21, in <module>
    create_key=_descriptor._internal_create_key,
AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key'

Doing a search for that error seems to indicate that there is a mismatch with protobuf, but I have ensured that the protobuf library and python protobuf are at the same version, 3.17.3. I have tried different versions of protobuf as well but keep hitting the same error. Could it be a mismatch of some sort between keras and tensorflow, as it seems to be failing on a tensorflow module? The same versions of protobuf are being used for both tensorflow and keras.

Thanks.

Please try to upgrade the protobuf version , after upgrading the pip version.

Just run this command. pip install –upgrade protobuf If you are using python 3 then run this command. pip3 install –upgrade protobuf. Thank you.