11

I'm getting this error when I'm running the following command to install tensorflow.

python3 -m pip install tensorflow-macos
ERROR: Failed building wheel for h5py
Failed to build h5py
ERROR: Could not build wheels for h5py, which is required to install pyproject.toml-based projects

I tired to install this wheel manually, from the official link (https://pypi.org/project/h5py/#files), it got installed properly but I'm still getting the same error.

I'm facing the above issue in Mac Book M1 chip.

vasilyrud
  • 825
  • 2
  • 10
  • 18
Lakshay Rohilla
  • 1,654
  • 6
  • 9
  • 30

3 Answers3

16

The official doc to use brew install.

$ brew install hdf5

If the above command gives you rosetta 2 issue, then run:-

arch -arm64 brew install hdf5   

Once, the h5py installation is done, run following 2 commands:-

$ export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.12.0_4 OR export HDF5_DIR=/opt/homebrew/opt/hdf5 (if hdf5 is installed in the "/opt/homebrew/opt/hdf5" location, you have to check it out first)
$ pip install --no-binary=h5py h5py

Note:- in the first command "1.12.0_4" is the version of hdfc installed in my system, you have to change it according to yours.

If you are getting the aforementioned error implies you must be using poetry.

Finally run:-

poetry install

We are running the above command, In case poetry wants to update anything.

Once we run poetry install, it might update existing libraries or download new libraries.

So we have to update poetry.lock file as well.

poetry lock
Lakshay Rohilla
  • 1,654
  • 6
  • 9
  • 30
2

After installing hdf5 try "export HDF5_DIR=/opt/homebrew/opt/hdf5"

Ref: https://github.com/h5py/h5py/issues/2035#issuecomment-1028226141

petrcherni
  • 21
  • 1
1

This works for me:

  1. Install brew (https://brew.sh/)
  2. brew install hdf5
  3. export HDF5_DIR=$(brew --prefix hdf5) (as @sgt pepper said)
  4. pip install --no-binary=h5py h5py