Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'keras' for Jupyter Notebook

I was running Jupyter Notebook and the following error occurs

ModuleNotFoundError
Traceback (most recent call last) in ---->

from keras.models import Sequential

from keras.layers import (
Conv2D, MaxPooling2D, Flatten, Dense, Dropout)

ModuleNotFoundError: No module named 'keras'

I have tried using import sys; sys.path and found this

['/home/xxx/notebook',
 '/home/xxx/anaconda3/lib/python37.zip',
 '/home/xxx/anaconda3/lib/python3.7',
 '/home/xxx/anaconda3/lib/python3.7/lib-dynload',
 '',
 '/home/xxx/anaconda3/lib/python3.7/site-packages',
 '/home/xxx/anaconda3/lib/python3.7/site-packages/IPython/extensions',
 '/home/xxx/.ipython']

Is there any problem with the installation? Do I need to reinstall everything from python to anaconda. Would some be able to point me to a proper installation of anaconda

BTW, if u have installed python, should you install python package through anaconda again

Thanks

like image 853
user1538798 Avatar asked Jun 18 '19 02:06

user1538798


2 Answers

You have to install all the dependencies first before using it. Try using

  • conda install tensorflow
  • conda install keras

by installing it with conda command it manage your versions compatibility with other libraries.

with pip install libraries will only install in your current environment and the latest version of the library sometimes latest libraries are not compatible with the other libraries so we have to take care of version compatibility.

like image 78
Sohaib Anwaar Avatar answered Oct 06 '22 14:10

Sohaib Anwaar


keras is actually part of tensorflow so all you have to do is just

from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Dense,Dropout,Activation, Flatten, Conv2D, MaxPooling2D

cheers mate

like image 11
Aaron Avatar answered Oct 06 '22 14:10

Aaron