【问题标题】:Failed to build h5py on mac M1在 mac M1 上构建 h5py 失败
【发布时间】:2022-01-11 16:31:14
【问题描述】:

我正在尝试在 python 虚拟环境中安装 AlphaFold。在尝试安装依赖项时,我收到此错误:

    ERROR: Could not find a version that satisfies the requirement tensorflow==1.14 (from versions: none)
ERROR: No matching distribution found for tensorflow==1.14

为了解决这个问题,我运行命令:“ pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.14.0-py3-none-any.whl

但在执行此操作时,我会收到一条很长的错误消息:

 In file included from /private/var/folders/r_/bgrrl1md0s5gx95p0q8qjj8h0000gn/T/pip-install-kh7jhw3_/h5py_4b8d652f3fda4ea0a05597c3cbb46b5b/h5py/defs.c:734:
  ./h5py/api_compat.h:27:10: fatal error: 'hdf5.h' file not found
  #include "hdf5.h"
           ^~~~~~~~
  1 error generated.
  error: command '/usr/bin/clang' failed with exit code 1
  ----------------------------------------
  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

我尝试了以下命令,但没有成功并出现同样的错误:

"brew install hdf5" (它已安装,但 h5py 安装仍然无法找到 hdf5.h 文件) “sudo -H pip3 安装 h5py” “点安装 h5py”

【问题讨论】:

    标签: python tensorflow hdf5 apple-m1 h5py


    【解决方案1】:

    您需要先导出HDF5_DIR 环境变量。

    运行:

    $ export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.12.1/
    $ pip install --no-binary=h5py h5py
    

    【讨论】:

    • 确认这对我有用。就我而言,我试图通过pip install tensorflow-macos 安装 TensorFlow,但我遇到了与 OP 相同的错误。导出HDF5_DIR 为我修复了它(我不必使用--no-binary 标志)。
    【解决方案2】:
    1. brew install hdf5

    2. ls /opt/homebrew/Cellar/hdf5/获取版本号,我的是1.13.0

    3. 导出该目录以便 h5py 可以看到它:

      export HDF5_DIR=/opt/homebrew/Cellar/hdf5/[version number]/

      我的是:export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.13.0/

    4. 尝试再次安装 pip(tensorflow 或 h5py)。

    【讨论】: