keras: ImportError: No module named h5py
on Ubuntu 14.04.5 LTS
installed keras from scratch as below :
- installed Cuda Toolkit 7.5
- installed cuDNN v4
- installed python-pip, python-dev using apt-get
- installed tensorflow 0.9.0 (later upgraded to 0.9.0rc)
- installed keras by downloading from here https://github.com/fchollet/keras.git
and extract, and typing command line :
sudo pip install keras
however, it didn’t work properly, I remembered it was a scipy problem so I installed scipy and
again tried to install keras by the same command : sudo pip install keras
but I only got these messages :
Requirement already up-to-date: keras in /usr/local/lib/python2.7/dist-packages Requirement already up-to-date: theano in /usr/local/lib/python2.7/dist-packages (from keras) Requirement already up-to-date: pyyaml in /usr/local/lib/python2.7/dist-packages (from keras) Requirement already up-to-date: six in /usr/local/lib/python2.7/dist-packages (from keras) Requirement already up-to-date: numpy>=1.7.1 in /usr/local/lib/python2.7/dist-packages (from theano->keras) Requirement already up-to-date: scipy>=0.11 in /usr/local/lib/python2.7/dist-packages (from theano->keras) Cleaning up…
and on the terminal by typing “python” I tried to import Sequential from keras.models only to check if keras was installed properly but got theses errors :
File “<stdin>”, line 1, in <module> File “keras/init.py”, line 4, in <module> from . import engine File “keras/engine/init.py”, line 3, in <module> from .topology import InputSpec File “keras/engine/topology.py”, line 17, in <module> from …utils.io_utils import ask_to_proceed_with_overwrite File “keras/utils/io_utils.py”, line 3, in <module> import h5py
Originally, the error occured when importing module backend so I upgraded my tensorflow and after that the above errors occured. (I edited the home./keras/keras.json to change the backend from theano to tensorflow)
I installed anaconda just because it is equipped with many useful python packages but it didn’t work for this problem.
What should I do?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 34 (2 by maintainers)
Have you tried directly installing h5py? http://docs.h5py.org/en/latest/build.html
Try running
pip install h5py
I got the problem while I adopt acenewgate’s opinion, but it’s not matter. The following solve my problem. (My environment is ubuntu 14.04)
sudo pip install cython
sudo apt-get install libhdf5-dev
sudo pip install h5py
solved problems by first installing libhdf5 and then installing h5py
sudo apt-get install libhdf5
sudo pip install h5py
thanks to both of youyou can only type: sudo apt-get install python-h5py
@krishnadusad after
pip3 install h5py
restarting the jupyter notebook solves the problem.In Jupyter, I didn’t want to restart my kernel after
!pip install h5py
(because I wanted to save that model!). This allowed me to continue without restarting:Update for Python 2.7 users:
reload
is a built-in so you don’t need to import it before calling it.pip install h5py pip install cython
solved my problem in Windows 10
I can run h5py tests but Keras still gives me errors. Any ideas on what could help?
Update 1: Restarting jupyter notebook/ restarting my computer fixed it.
On windows 10, I executed
But I still get the same error.
I tried to import h5py directly and test it, then I get this error:
UPDATE: ok…so I uninstalled h5py and then reinstalled it and restarted anaconda. Now its working!!!
I recently had the same problem… I was executing a python script from a bash file… I used python3 , on which I didn’t have h5py installed.
pip3 install h5py
solved my problem.
This issue is happening because of different version of keras and h5py.
Steps to solve
Remove “h5py” if you already installed
pip uninstall h5py
Remove keras
pip uninstall keras
3 . Now, Install keras, This will install updated and same version of keras and h5py
pip install keras
Same problem on Debian and python2
If that fails then you may also need libhdf5 😃
@wt-huang please close this issue, we’re repeating the same thing over and over.
Just for your information. I am using Raspberry pi (Raspbian Stretch) when I have the similar issue showing that keras can not load module h5py
By doing the following solved my problem:
sudo apt-get install libhdf5-dev
@iamtodor maybe you should try it in your workspace. In my case, I tried
pip install h5py
in anaconda prompt. But it still error in Tensorflow Spyder. So i add h5py in tensorflow by following, then it works.activate tensorflow
pip install h5py
just to summarize, you need to install:
pip install h5py
If it does not help, please restart your jupyther notebook or computer.
@colllin It is solved. Actually, I did not need to import reload (it was imported). so, I just ran reload(keras.models) and then I could save my models.
Can’t reproduce this issue with Keras (2.0.5) and Python 3.6.1
pip install h5py
worked well for me