I have keras installed on my linux machine, but when I try to import a dataset from the keras.datasets I get an error that it cannot find it.
So for example:
from keras.datasets import mnist
I get the error
ImportError: No module named keras.datasets
I installed keras using pip install and it installed successfully.
Do you have keras.py or keras.pyc in the current working directory? If so, this will mess up the imports. Try renaming the file and/or deleting keras.pyc.
Indeed the problem was that I had multiple versions of Python.
Removing Anaconda Python and installing all libraries using pip / apt-get instead of conda solved my problem.
I found this to be true but it is not necessary to delete anaconda. I had the same issue but with multiple python versions. However, i created an environment that only used the Anaconda version (while in that 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 simply the name of the environment you created. To access this, just use the command
source activate dataweekends
Be mindful that you might (probably) have to reinstall dependencies once in that 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 you do in python.
Thanks to the comment from Selcuk which got me on the right track.
Indeed the problem was that I had multiple versions of Python. I followed some online instructions to installing Keras which recommended installing MiniConda/Conda/Anaconda which is its own version of python. So I had two Python2.7 versions installed:
Removing Anaconda Python and installing all libraries using pip / apt-get instead of conda solved my problem.