h5py: Fails to build from source on MacOS 11 + M1
- Operating System: MacOS 11.2
- Python Version: 3.9.1
- h5py version: 3.1.0
- HDF5 version: 1.12.0
Attempting to install h5py via pip fails for ARM Macs; there is no prebuilt wheel for this platform, so pip attempts to build h5py from source. However, this fails because it attempts to use Numpy 1.19.3 (when on Python 3.9), but Numpy 1.19.3 does not build on M1 Macs out of the box (build log: h5py_build_fail.log).
If you modify setup.py so that h5py builds against Numpy 1.20.1 instead (which works on M1 Macs), h5py builds successfully.
Dumb example patch that fixes the build but isn’t intended to be actually merged:
diff --git a/setup.py b/setup.py
index cc583bc9..9c0400cc 100755
--- a/setup.py
+++ b/setup.py
@@ -29,7 +29,7 @@ NUMPY_MIN_VERSIONS = [
# Numpy Python
('1.14.5', "=='3.7'"),
('1.17.5', "=='3.8'"),
- ('1.19.3', ">='3.9'"),
+ ('1.20.1', ">='3.9'"),
]
# these are required to use h5py
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 17 (7 by maintainers)
I found an alternative solution:
I have found that pip install only works if you have installed hdf5 separately first on the Mac M1. This was possible through brew but not pip.
Steps:
@WillTrojak Your fix worked! I also needed to do
export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.12.1/and then follow the steps from here to build itSorry to reopen an old issue, but I had this same problem trying to install h5py and I think I came up with a bit of dirty fix. More than happy for someone to point out a more elegant fix.
The issue for me at least seemed to be with numpy 1.19.3 failing to build. With homebrew numpy 1.20.3 is available, but even with that install the build for h5py will try and build 1.19.3.
By cloning the current master, then bumping the numpy version to 1.20.3 in setup.py, this seemed to get round the issue.
This may have some side effects, but at least it works for now.