如何使用 M1 在 MacOS 上安装 h5py(Keras 所需)?

Rac*_*ole 36 python hdf5 h5py keras apple-m1

我有一台 M1 MacBook。我已经使用 pyenv 安装了 python 3.9.1,并且 pip3 版本为 21.0.1。我已经通过安装了自制程序和 hdf5 1.12.0_1 brew install hdf5

当我打字时

pip3 install h5py
Run Code Online (Sandbox Code Playgroud)

我收到错误:

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
Run Code Online (Sandbox Code Playgroud)

我看到它libhdf5.dylib存在于 中/opt/homebrew/opt/hdf5/lib,所以我事先尝试过export LDFLAGS="-L/opt/homebrew/opt/hdf5/lib"export CPPFLAGS="-L/opt/homebrew/opt/hdf5/include"但它们没有帮助。

如何安装h5py?

我实际上安装 h5py 作为安装 Keras 的要求。

谢谢!

小智 81

这对我有用:

$ brew install hdf5
$ export HDF5_DIR="$(brew --prefix hdf5)"
$ pip install --no-binary=h5py h5py
Run Code Online (Sandbox Code Playgroud)


小智 15

尝试使用 conda 安装 h5py。对我有用。

conda install h5py
Run Code Online (Sandbox Code Playgroud)