Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: The h5py Python package is required to use pre-built Keras models #361

Closed
holgerbrandl opened this issue Apr 12, 2018 · 10 comments
Closed

Comments

@holgerbrandl
Copy link

holgerbrandl commented Apr 12, 2018

To reproduce the issue start a docker container

docker pull rocker/tidyverse
docker run -it rocker/tidyverse /bin/bash --login

within docker prep python and install keras package in R

## prep python installation (pip, virtualenv are needed for install_keras)
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py

pip install virtualenv
pip install h5py

Rscript - <<"EOF"
install.packages("keras")
library(keras)
install_keras()

conv_base <- application_vgg16(weights = "imagenet", include_top = FALSE, input_shape = c(150, 150, 3))
summary(conv_base)
EOF

Which finally reports

Installation complete.

Error: The h5py Python package is required to use pre-built Keras models
Execution halted

So I've checked if the h5py package is correctly installed:

# python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import h5py
/usr/local/lib/python3.5/dist-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

Which looks OKish. What am I doing wrong?

The issue seems related to https://stackoverflow.com/questions/46819212/error-in-r-the-h5py-python-package-is-required-to-save-and-load-models but none of the suggested workarounds seem to solve the problem

@obarisk
Copy link

obarisk commented Jul 9, 2018

It's failed in have_h5py() function.
reticulate requires libpython3.x depending on your python version.

@stenpiren
Copy link

i am having the same issue!

@skeydan skeydan closed this as completed Sep 11, 2018
@ras44
Copy link

ras44 commented Sep 25, 2018

I am having the same issue and don't see a resolution in this thread- @skeydan any reason this was closed? Could you point me to the solution if its in this thread? I've tried to implement everything above but still have the same problem. Thank you!

@ras44
Copy link

ras44 commented Sep 25, 2018

@skeydan this worked for me:

sudo ln -s /usr/lib64/libpython2.7.so.1.0 /usr/lib64/libpython2.7.so

Solution description:

@obarisk mentioned:

reticulate requires libpython3.x depending on your python version

I created an R test script with reticulate to make sure that worked:

# reticulate test script
library(reticulate)
os <- import("os")
os$listdir(".")

If failed, initially with:

# Python shared library '/usr/lib64/libpython2.7.so' not found, Python bindings not loaded.

This indicates the libraries are missing from /usr/lib64/.... So I created a symbolic link as above to make the link to the python 2.7 libs. FYI this was on CentOS 6/7.

@skeydan
Copy link

skeydan commented Sep 25, 2018

Thanks for posting your solution!
(This was closed as part of a batch close of inactive issues, in order get an overview of what's still active.)

@paulexcoff
Copy link

paulexcoff commented Feb 4, 2020

I had this exact issue from trying to run Keras without installing tensorflow. So if someone else has this issue, make sure you've installed tensorflow

`
install.packages("tensorflow")

library(tensorflow)

install_tensorflow()
`

@luostrowski
Copy link

I'm having the same problem..

I have tensorflow installed but I get the following error when I try to run the load_model_hdf5 function:

Error in load_model_hdf5(model_file): The h5py Python package is required to save and load models

@ras44
Copy link

ras44 commented Mar 8, 2024

hi @luostrowski a couple thoughts that might help:

@t-kalinowski
Copy link
Member

@luostrowski

  • Can you please open a new issue? (This one is quite old, much has changed since this was first opened)
  • How did you install keras? keras::install_keras() should also install h5py.

@luostrowski
Copy link

Hi @ras44 and @t-kalinowski,

Thank you both for the replies!

I figured it out the problem, somehow the code was importing Python in a virtual environment different than the one I had h5py installed. Once I adjusted this, the script worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants