我尝试在运行 Python 2.7 的 CentOS 7 系统上通过 pip 安装 NetCDF4。以下 HDF5 软件包已通过 yum 安装:
[user@host]$ rpm -qa | grep hdf5
hdf5-openmpi-1.8.12-12.el7.x86_64
hdf5-1.8.12-11.el7.x86_64
尽管已经安装了软件包,但我在尝试安装 hdf5 时仍然遇到此错误:
[user@host]$ pip install -r requirements.txt
.
.
.
Collecting netCDF4>=1.1.1 (from -r requirements.txt (line 9))
Using cached https://files.pythonhosted.org/packages/79/0d/caa957cc1b42b718ce4b9b3e849e6f7aa99faad2d522d8f2d7a33500fba0/netCDF4-1.5.6.tar.gz
ERROR: Command errored out with exit status 1:
command: /home/ooiui/miniconda2/envs/ooiui279/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-cOs19I/netCDF4/setup.py'"'"'; __file__='"'"'/tmp/pip-install-cOs19I/netCDF4/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
cwd: /tmp/pip-install-cOs19I/netCDF4/
Complete output (30 lines):
Package hdf5 was not found in the pkg-config search path.
Perhaps you should add the directory containing `hdf5.pc'
to the PKG_CONFIG_PATH environment variable
No package 'hdf5' found
reading from setup.cfg...
HDF5_DIR environment variable not set, checking some standard locations ..
checking /home/ooiui/miniconda2/envs/ooiui279/include ...
hdf5 headers not found in /home/ooiui/miniconda2/envs/ooiui279/include
checking /home/ooiui/miniconda2/envs/ooiui279/Library/include ...
hdf5 headers not found in /home/ooiui/miniconda2/envs/ooiui279/Library/include
checking /home/ooiui/include ...
hdf5 headers not found in /home/ooiui/include
checking /usr/local/include ...
hdf5 headers not found in /usr/local/include
checking /sw/include ...
hdf5 headers not found in /sw/include
checking /opt/include ...
hdf5 headers not found in /opt/include
checking /opt/local/include ...
hdf5 headers not found in /opt/local/include
checking /usr/include ...
hdf5 headers not found in /usr/include
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-cOs19I/netCDF4/setup.py", line 425, in <module>
_populate_hdf5_info(dirstosearch, inc_dirs, libs, lib_dirs)
File "/tmp/pip-install-cOs19I/netCDF4/setup.py", line 366, in _populate_hdf5_info
raise ValueError('did not find HDF5 headers')
ValueError: did not find HDF5 headers
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
过去,当我在 CentOS 6 上安装 NetCDF4 时,我不需要进行任何特殊的调整。有什么变化需要额外的准备吗?预先感谢。
感谢 phd,我安装了 HDF5 标头,并将 HDF5_DIR 环境变量设置为 /include 以反映安装位置。现在我似乎遇到了 NetCDF4 本身的类似障碍:
Collecting netCDF4>=1.1.1 (from -r requirements.txt (line 9))
Using cached https://files.pythonhosted.org/packages/79/0d/caa957cc1b42b718ce4b9b3e849e6f7aa99faad2d522d8f2d7a33500fba0/netCDF4-1.5.6.tar.gz
ERROR: Command errored out with exit status 1:
command: /home/ooiui/miniconda2/envs/ooiui279/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-l853Xs/netCDF4/setup.py'"'"'; __file__='"'"'/tmp/pip-install-l853Xs/netCDF4/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
cwd: /tmp/pip-install-l853Xs/netCDF4/
Complete output (23 lines):
Package hdf5 was not found in the pkg-config search path.
Perhaps you should add the directory containing `hdf5.pc'
to the PKG_CONFIG_PATH environment variable
No package 'hdf5' found
reading from setup.cfg...
checking /usr/include ...
HDF5 library version: 1.8.12 headers found in /usr/include
HDF5 library version: 1.8.12 found in /usr
NETCDF4_DIR environment variable not set, checking standard locations..
checking /home/ooiui/miniconda2/envs/ooiui279 ...
checking /home/ooiui/miniconda2/envs/ooiui279/Library ...
checking /home/ooiui ...
checking /usr/local ...
checking /sw ...
checking /opt ...
checking /opt/local ...
checking /usr ...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-l853Xs/netCDF4/setup.py", line 441, in <module>
raise ValueError('did not find netCDF version 4 headers')
ValueError: did not find netCDF version 4 headers
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
我们正在尝试根据requirements.txt文件通过pip安装NetCDF4,但它似乎因缺少NetCDF4标头而失败。
ValueError:未找到 HDF5 标头
该错误表示没有开发文件。您有库,但没有标头。安装:
yum install hdf5-devel
开发安装值得尝试。对于 ubuntu,我遇到了相同的 HDF5_DIR 错误,并解决了以下问题
sudo apt-get install libnetcdf-dev