Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'keras.models'; 'keras' is not a package

Tags:

keras

Keras program with error

I am a beginner in Keras. I installed Anaconda with Python 3.6, then installed Tensorflow and ran some models I found on the Internet. Then I just found out about Keras which is just what I need to learn about Neural Networks. I installed Keras and it didn't have any errors. Then I found a short simple XOR model using Keras but it just didn't work and complained that it doesn't know what Keras is?? I hope someone may be able to help.

like image 494
Ray Van Raamsdonk Avatar asked Jan 24 '18 08:01

Ray Van Raamsdonk


2 Answers

The problem is that you have a file named "keras.py" and this shadows the real keras package. Don't do that, never name a python script the same as a package.

Solution is to rename your keras.py script into a different name.

like image 194
Dr. Snoopy Avatar answered Sep 23 '22 21:09

Dr. Snoopy


Because keras is under tensorflow, instead of:

from keras.models import Sequential

...try:

from tensorflow.keras.models import Sequential 
like image 25
Susana Isabel Santos Avatar answered Sep 24 '22 21:09

Susana Isabel Santos