Cannot run keras

2019-08-02 21:33发布

问题:

I want to run keras on anaconda for convolution neural network using mnist handwriting recognition. A day before everything worked fine but as I try to run the same program, i get the following error in the first line:

from keras.datasets import mnist (first line of code)

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

I also created virtual environment to use python 3.5 as my python version is 3.6. I have installed both keras and tensorflow. How do i fix the above error? Perhaps it is related to path and not error with keras. My anaconda is installed in E: whearas working environment is C:\Users\Prashant Mahato.

回答1:

Do you get an error message if you just import keras? I was getting a similar error in the command line and then implemented in Spyder (using Anaconda) and it worked fine.



回答2:

Here is how I install Keras and other related dependencies

conda create -n <Environment_Name> python=3.6
activate <Environment_Name>
conda update --all 
conda install  mingw libpython
conda install  scipy
conda install  numpy
conda install  mkl
conda install  -c conda-forge tensorflow
conda install  theano
pip install  pyyaml
pip install  h5py
pip install  keras
conda install -c conda-forge  tmux
conda install  pandas
condas install  pillow
conda  install  scikit-learn
conda install  -c menpo opencv3

To check if everything is work as it should just import all the packages in python within the environment created.

I'm running Windows 10 and Anaconda 4.2

If running Ubuntu, replace

activate <Environment_Name>

with

source activate <Environment_Name>

HTH.