If you use TensorFlow 2.16+ and have an error with Keras 3, to keep using Keras 2, you can first install tf-keras, and then set the environment variable TF_USE_LEGACY_KERAS=1 directly or in your python program with import os;os.environ["TF_USE_LEGACY_KERAS"]="1". [Reference]