Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install h5py (needed for Keras) on MacOS with M1?

I have an M1 MacBook. I have installed python 3.9.1 using pyenv, and have pip3 version 21.0.1. I have installed homebrew and hdf5 1.12.0_1 via brew install hdf5.

When I type

pip3 install h5py

I get the error:

Requirement already satisfied: numpy>=1.19.3 in /Users/.../.pyenv/versions/3.9.1/lib/python3.9/site-packages (from h5py) (1.20.0)
Building wheels for collected packages: h5py
  Building wheel for h5py (PEP 517) ... error

  Loading library to get build settings and version: libhdf5.dylib
  error: Unable to load dependency HDF5, make sure HDF5 is installed properly
  error: dlopen(libhdf5.dylib, 6): image not found
  ----------------------------------------
  ERROR: Failed building wheel for h5py

I saw that libhdf5.dylib is present in /opt/homebrew/opt/hdf5/lib, so I tried export LDFLAGS="-L/opt/homebrew/opt/hdf5/lib" and export CPPFLAGS="-L/opt/homebrew/opt/hdf5/include" beforehand but they don't help.

How can I install h5py?

I am actually installing h5py as a requirement to install Keras.

Thanks!

like image 672
Racing Tadpole Avatar asked Mar 22 '21 07:03

Racing Tadpole


People also ask

How do I download h5py?

On OSX/MacOS, h5py can be installed via Homebrew, Macports, or Fink. The current state of h5py in various Linux Distributions can be seen at https://pkgs.org/download/python-h5py, and can be installed via the package manager.


2 Answers

This works for me:

$ brew install hdf5
$ export HDF5_DIR="$(brew --prefix hdf5)"
$ pip install --no-binary=h5py h5py
like image 137
user15990707 Avatar answered Nov 06 '22 15:11

user15990707


Try to install h5py using conda. Works for me.

conda install h5py
like image 40
Vasantharajan Charangan Avatar answered Nov 06 '22 17:11

Vasantharajan Charangan