macOS M1 Pro 安装 h5py

安装 TensorFlow 时,遇到一个依赖 h5py,这个包无论如何无法成功安装,报错无任何可用信息:

这就很难办了,查看日志发现原来是没有针对 m1 的二进制包,自动进行编译了。但编译报错说找不到头文件:

于是使用 brew 安装缺少的库,搜索之下,还真有: brew install hdf5 ,安装后再次执行 h5py 的安装,还是一样的报错,显然还是找不到。

此时使用命令 find /opt -iname "*hdf5.h*" 查找,应该能找到 /opt/homebrew/include/hdf5.h 这个路径,使用以下命令添加相关环境变量:

再次执行命令安装 h5py: python3 -m pip install h5py

终于安装成功。

本文由 落格博客 原创撰写:落格博客 » macOS M1 Pro 安装 h5py

转载请保留出处和原文链接:https://www.logcg.com/archives/3548.html

About the Author

R0uter

如非声明,本人所著文章均为原创手打,转载请注明本页面链接和我的名字。

Comments

  1. Iam getting this error after executing the cammand :

    Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!
    To rerun under ARM use:
    arch -arm64 brew install …
    To install under x86_64, install Homebrew into /usr/local.

    Upon trying the command again:
    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

    1. make sure ur terminal running on arm mode instead of Rosetta. And delete the Homebrew thing under /usr/local, arm version of brew installed at /opt/homebrew

      I think u need to clean out your env path settings, the intel env confusing them.

  2. I did as you instructed but, still get:

    ERROR: Could not build wheels for h5py, which is required to install pyproject.toml-based projects

    The above error is generated after running this command for the second time: python3 -m pip install h5py

    1. Did you try find /opt -iname "*hdf5.h*"
      see if there any results like /opt/homebrew/include/hdf5.h
      the main theory is h5py requiring hdf5, but it cant build itself, we have to install the library manually, then install h5py.

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注