Keras module not referenced

Hi everyone,

I am very new to Python/TensorFlow/Keras and just trying to learn something on my own, so I might not be able to describe my problems accurately…

So I am writing in Pycharm 2020, in a python 3.10 venv. I installed Tensorflow through pip install tensorflow, and the version got installed is 2.16. Then I attempted to pip install keras as well, but I found out that no keras folder created in my tensorflow folder, so the keras module was unreferenced. However, the keras folder showed up in a python folder within the tensorflow folder. So for me, the tensorflow.keras line would show as a bug but tensorflow.python.keras line would not report bug. Nonetheless, when I attempted to run the script, I got an error message "line 5, in
from tensorflow.python.keras.layers import Dense, LSTM
ImportError: cannot import name ‘LSTM’ from ‘tensorflow.python.keras.layers’ (/Users/guangyu/PycharmProjects/money making/venv/lib/python3.12/site-packages/tensorflow/python/keras/layers/init.py). Did you mean: ‘LSTMV1’?

Process finished with exit code 1"

Any experienced coder has any idea what might happened here?

Many thanks,

from tensorflow.python.keras.layers import Dense, Dropout,Activation

from tensorflow.python.keras.layers.recurrent import LSTM

works for me

1 Like

Hi @Liu_Liu, when you install Tensorflow 2.16.1 using pip by default Keras 3.0 will be installed and you can import Keras directly by using `import keras’

Thank You.

1 Like

Just adding up to this comment for OP.

It takes a while to get the relationship bw keras and tf, especially in Keras v3.

Keras is a symbolic/descriptive layer on top of different possible backends, one of which is tensorflow, and as @Kiran_Sai_Ramineni it’s imported independently, as you can see in the Keras docs.