如何在带有 M1 的 MacOS 上安装 h5py(Keras 需要)?

问题描述 投票:0回答:3

我有一台 M1 MacBook。我已经使用 pyenv 安装了 python 3.9.1,并且有 pip3 版本 21.0.1。 我已经通过

brew install hdf5
安装了自制软件和hdf5 1.12.0_1。

当我打字时

pip3 install h5py

我得到错误:

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

我看到

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 的要求。

谢谢!

python keras hdf5 h5py apple-m1
3个回答
77
投票

这对我有用:

$ brew install hdf5
$ export HDF5_DIR="$(brew --prefix hdf5)"
$ pip install --no-binary=h5py h5py

14
投票

尝试使用 conda 安装 h5py。为我工作。

conda install h5py

0
投票

您可以按照以下步骤在 macOS M1 上安装

hdf5

第 0 步(可选):如果已安装,请使用

hdf5
卸载
brew

brew uninstal hdf5 --ignore-dependencies  

第 1 步:使用

hdf5
安装
brew
.

arch -arm64 brew install hdf5

第二步:找到

hdf5
hdf5.h
的目录。

sudo find / -iname "*hdf5.h*" # use sudo if possible

在我的笔记本电脑上,输出是

/usr/local/include/hdf5.h
/usr/local/Cellar/hdf5/1.12.2_2/include/hdf5.h
/usr/local/Cellar/opencv/4.7.0_2/include/opencv4/opencv2/flann/hdf5.h
/usr/local/Cellar/vtk/9.2.6/include/vtk-9.2/vtk_hdf5.h
/System/Volumes/Data/usr/local/include/hdf5.h
/System/Volumes/Data/usr/local/Cellar/hdf5/1.12.2_2/include/hdf5.h
/System/Volumes/Data/usr/local/Cellar/opencv/4.7.0_2/include/opencv4/opencv2/flann/hdf5.h
/System/Volumes/Data/usr/local/Cellar/vtk/9.2.6/include/vtk-9.2/vtk_hdf5.h

第 3 步:设置

CPATH
HDF5_DIR
.

export CPATH=$CPATH:/usr/local/include/:/usr/local/Cellar/hdf5/1.12.2_2/include

export HDF5_DIR=/usr/local/Cellar/hdf5/1.12.2_2

请注意,在您的笔记本电脑上,这些目录可能不同。

第 4 步:使用

hdf5
安装
pip
.

arch -arm64 pip3.9 install hdf5

然后成功完成安装。

© www.soinside.com 2019 - 2024. All rights reserved.