Rohit Singh
Rohit Singh

Reputation: 63

ModuleNotFoundError: No module named 'keras' Can't import keras

I have tried reinstalling anaconda. I also tried uninstalling and reinstalling keras. I have tensorflow 2.3.0 and keras 2.4.3 installed. But I just can't seem to be able to import keras. This is my import statement.

from keras.models import Sequential
from keras.layers import Dense, LSTM
from pandas import DataFrame, concat
from sklearn.preprocessing import MinMaxScaler

And I get the error

ModuleNotFoundError: No module named 'keras'

I also tried installing them in different anaconda environments but it just doesn't seem to work. I am trying to make a deep learning model. Any help would be greatly appreciated.

Upvotes: 0

Views: 5523

Answers (3)

DapperDuck
DapperDuck

Reputation: 2859

I would recommend running the following pip commands:

pip install tensorflow
pip install keras

If it says they are already installed, add --upgrade to the end of the line. If you are using a notebook, replace pip with !pip.

Then using the following imports:

import tensorflow as tf
import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, LSTM
#Other imports

Upvotes: 1

krenerd
krenerd

Reputation: 791

I would first like to ask you whether only Tensorflow/Keras is broken.

An obvious reason for a ModuleNotFoundError problem is that Keras is not reachable by Python library lookups. Although this is a common problem everybody has experienced, the primary solution is simple.

You can check installed packages in the command prompt by pip freeze. If you are sure installed the package, you must add the full directory of libraries to the PATH variable. Refer to here on how to add to the PATH variable.

In case you already done that, and doesn't solve your problem, refer to here,

Upvotes: 1

mkloster
mkloster

Reputation: 31

With tensorflow 2.X keras is a part of tensorflow

maybe try:

from tensorflow import keras

and remove keras Its not so good too run keras and tensorflow in one enviroment

Upvotes: 1

Related Questions