Import keras.datasets not working

I have keras installed on my linux machine, but when I try to import a dataset from keras.datasets, I get an error message that it cannot find.

So for example:

from keras.datasets import mnist 

I get an error

ImportError: no module named keras.datasets

I installed keras using pip install and successfully installed it.

+7
python linux theano python-import keras
source share
3 answers

In fact, the problem was that I had several versions of Python.

Removing Anaconda Python and installing all the libraries using pip / apt-get instead of conda solved my problem.

I found this to be true, but there is no need to remove anaconda. I had the same issue, but with multiple versions of python. However, I created an environment that used only the version of Anaconda (while in this environment). In terminal (on Mac and other suitable terminals) type / copy

conda create -n dataweekends python=2.7 pandas scikit-learn jupyter matplotlib

dataweekends is just the name of the environment you created. To access this, simply use the command

source activate dataweekends

Remember that you (may) have to reinstall dependencies once in this new environment.

I got this trick from here https://www.dataweekends.com/blog/2017/03/09/set-up-your-mac-for-deep-learning-with-python-keras-and-tensorflow "

I would also recommend setting up different environments for each project that you are running in python.

+1
source share

Do you have keras.py or keras.pyc in the current working directory? If so, it will ruin the import. Try renaming the file and / or deleting keras.pyc .

+1
source share

Thanks to a comment from Selcuk that got me on the right track.

Indeed, the problem was that I had several versions of Python. I followed some online Keras installation instructions that recommended installing MiniConda / Conda / Anaconda, which is its own version of python. So, I had two versions of Python2.7:

  • Plain Linux Python 2.7
  • Anaconda Python 2.7

Removing Anaconda Python and installing all the libraries using pip / apt-get instead of conda solved my problem.

0
source share

All Articles