在macOS上安装pygrib
报错信息
pygrib 是一个用于读取和写入气象数据格式 .grib 的 Python 库,在 macOS 上安装时遇到如下报错:
src/pygrib/_pygrib.c:1256:10: fatal error: 'grib_api.h' file not found
#include "grib_api.h"
^~~~~~~~~~~~
214 warnings and 1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pygrib
Failed to build pygrib
ERROR: Could not build wheels for pygrib, which is required to install pyproject.toml-based projects
参考方案
这个 issue 提出了类似的问题,平台是 Ubuntu。其解决方案如下:
sudo apt install libeccodes-dev
pip install eccodes-python
解决方案
同样的思路迁移至 macOS,通过 homebrew 安装 eccodes,并通过 pip 安装 eccodes-python,最终成功安装。
brew install eccodes
pip install eccodes-python
此外,注意到 eccodes 包需要 hdf5 包作为依赖,同某些包依赖的 hdf5-mpi 形成冲突,后期需要注意。