问题
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
回答1:
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.
回答2:
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
回答3:
If you have installed all the required packages in a virtual/conda environment, have you tried saving the environment as an ipython kernel? I got those errors when I tried to launch a jupyter notebook from my virtual environment but I hadn't explicitly created a kernel for it.
https://ipython.readthedocs.io/en/stable/install/kernel_install.html
回答4:
Install packages in Anaconda Navigator -> Enviroments -> Play button -> Open Terminal -> conda install keras
回答5:
Create a virtual environment and install all packages and specially jupyter-notebook in it. Some times it is necessary to install jupyter-notebook in each virtual environment to work properly with other libraries. It is preferred to use anaconda.
After creating your virtual env use this command to install jupyter:
conda install -c anaconda jupyter
来源:https://stackoverflow.com/questions/56641165/modulenotfounderror-no-module-named-keras-for-jupyter-notebook