Pycharm problem with hub.keraslyer intransfer learning

below is my code, it’s running normally in google colab but it’s giving error in pycharm.
the code is:
import tensorflow as tf
import tensorflow_hub as hub
model_url = “mobilenet_v2 | Kaggle
feature_extract_layer=hub.KerasLayer(model_url,trainable=False,input_shape=(224,224,3),name=“feature_extraction”)
model=tf.keras.Sequential([
feature_extract_layer,
tf.keras.layers.Dense(train_data.num_classes,activation=‘softmax’,name=“outputLayer”)

])
model.summary()

the error is:
Only instances of keras.Layer can be added to a Sequential model

knowing that it’s runing normaly in google colab

the solution is to make sure that keras is version 2.something : Since TF2.16 comes with Keras3 the problem arises. As a workaround, we can install tf_keras package and set environment variable TF_USE_LEGACY_KERAS=1 to ensure Keras2 will be used with tf.keras.