I have install all below dependency before installing keras.
numpy, scipy
pyyaml
Theano
HDF5 and h5py.
Still I am getting following error if I try to import keras module.
Traceback (most recent call last):
File "", line 2195, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "/home/ttpc/keras.py", line 10, in
from keras.models import Sequential
I am using Ubuntu 14.04. Below is trace of my pip packages.
Cython==0.23.2
Keras==0.1.3
Pillow==2.3.0
PyYAML==3.11
Theano==0.7.0
beautifulsoup4==4.2.1
chardet==2.2.1
colorama==0.2.5
command-not-found==0.3
decorator==3.4.0
h5py==2.2.1
html5lib==0.999
language-selector==0.1
lxml==3.3.3
matplotlib==1.3.1
nose==1.3.1
numexpr==2.2.2
numpy==1.8.2
pandas==0.13.1
pycurl==7.19.3
pygobject==3.12.0
pyparsing==2.0.1
python-apt==0.9.3.5ubuntu1
python-dateutil==2.0
pytz==2012c
requests==2.2.1
scikit-learn==0.16.1
scipy==0.13.3
six==1.5.2
tables==3.1.1
tornado==3.1.1
ufw==0.34-rc-0ubuntu2
unattended-upgrades==0.1
urllib3==1.7.1
wheel==0.24.0
xgboost==0.4
Kindly help me out.
Maybe a PATH / PYTHONPATH issue? Just reinstall everything from scratch. Make sure that the Python you're calling is the same as the Python to which you're installing packages with pip (especially if you installed Anaconda).
In any case, this is not a Keras-related issue.
Your script seems to be named keras.py, causing python to think that is where you want to import from. Just rename your script and it should work.
you were spot on phreeza, indeed it was silly mistake. :)
I need urgent help!
I get this error from my code:
Traceback (most recent call last):
File "/Users/Zahra/code1", line 1, in
from keras.models import Sequential
ImportError: No module named keras.models
What does that mean?
I installed Anaconda, btw.
@zahrasorour
check your keras.json file in ~/.keras/ directory is exists.
hello friends
i have the same problem can you help me to know how to solve it
mportError Traceback (most recent call last)
1 #with keras
----> 2 from keras.models import Sequential
3 from keras.layers import Dense
ImportError: No module named keras.models
The solution for me was:
$pip3 install tensorflow
May be obvious, but I also got this issue when I named my Python file keras.py. File needs to be named something other than the package name.
File "test.py",
line 4, in
Your keras library maybe under tensorflow:
import like this:
from tensorflow.keras.models import Sequential
from numpy import loadtxt
from tensorflow.keras.models import Sequential
from keras.layers import Dense
dataset = loadtxt('pima-indians-diabetes.csv', delimiter=',')
X = dataset[:,0:8]
y = dataset[:,8]
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
'''# fit the keras model on the dataset
model.fit(X, y, epochs=150, batch_size=10, verbose=0)'''
model.fit(X, y, epochs=150, batch_size=10, verbose=0)
_, accuracy = model.evaluate(X, y, verbose=0)
predictions = model.predict_classes(X)
for i in range(5):
print('%s => %d (expected %d)' % (X[i].tolist(), predictions[i], y[i]))
I am also getting the same error. I am using Linux
Your keras library maybe under tensorflow:
import like this:
from tensorflow.keras.models import Sequential
Thanks dude馃!!
Most helpful comment
Your script seems to be named keras.py, causing python to think that is where you want to import from. Just rename your script and it should work.