如何使用 M1 在 MacOS 上安装 h5py(Keras 需要)? [英] How to install h5py (needed for Keras) on MacOS with M1?

查看:159
本文介绍了如何使用 M1 在 MacOS 上安装 h5py(Keras 需要)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台 M1 MacBook.我已经使用 pyenv 安装了 python 3.9.1,并且有 pip3 版本 21.0.1.我已经通过 brew install hdf5 安装了 homebrew 和 hdf5 1.12.0_1.

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.

当我打字时

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

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

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.

如何安装 h5py?

我实际上是在安装 h5py 作为安装 Keras 的要求.

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

谢谢!

推荐答案

这对我有用:

$ brew install hdf5
$ export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.12.0_4
$ pip install --no-binary=h5py h5py

这篇关于如何使用 M1 在 MacOS 上安装 h5py(Keras 需要)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆