[英]Python, NetCDF4 and HDF5
I don't know why these packages are always such a pain to install. 我不知道为什么这些软件包总是很难安装。 I have been using NetCDF/HDF5 for a long time now and it's always been a pure horror trip getting them to install or run properly, no matter if it's on Linux or OSX, no matter if C, C++ or now python. 我已经使用NetCDF / HDF5很长时间了,无论它们是在Linux还是OSX上,无论是C,C ++还是现在的python,无论如何都可以正常安装或运行它们,这始终是一次恐怖的旅行。 The simple dependency between netcdf4 and hdf5 is a source of great pain for many people and I really wish the developers of those packages would finally do something about it. netcdf4和hdf5之间的简单依赖关系为许多人带来了极大的痛苦,我真的希望那些软件包的开发人员最终对此有所帮助。
So, the latest concrete problem I am facing is this: I am trying to install netCDF4 for python. 因此,我面临的最新具体问题是:我正在尝试为python安装netCDF4。 I get the following error: 我收到以下错误:
Package hdf5 was not found in the pkg-config search path
Perhaps you should add the directory containing `hdf5.pc'
I tried to install the hdf5 packages using apt-get, including: 我试图使用apt-get安装hdf5软件包,包括:
Using pip, I tried: 我使用点子尝试:
pip install h5py
which failed miserably to resolve a dependency to Cython, which I then installed manually. 不幸的是无法解决对Cython的依赖,然后我手动安装了它。 After that it installed (apparently) but I can not find the file hdf5.pc anywhere. 之后,它安装了(显然),但是我在任何地方都找不到文件hdf5.pc。
I am pulling my hairs out here. 我在这里拔头发。 Anyone know how to work around this problem? 任何人都知道如何解决此问题?
When you mix distribution packages and self-built packages, you are increasing your chance of problems (as you are finding out). 当您将分发软件包和自建软件包混合使用时,您发现问题的机会就会增加。
Also, do you want h5py or do you want netcdf-python? 另外,您是否要使用h5py或netcdf-python? I don't think netcdf-python has a dependency on h5py. 我不认为netcdf-python对h5py有依赖性。 Rather, netcdf-python binds to the C netcdf library, which in turn depends on the C HDF5 library. 而是,netcdf-python绑定到C netcdf库,而C netcdf库又取决于C HDF5库。
h5py likewise binds to C HDF5 h5py同样绑定到C HDF5
There is a lot of software involved, it's true. 确实涉及很多软件。 Work your way through step by step and it will make more sense eventually (says the guy who has been doing this for 15 years... it gets easier!) 一步一步地工作,最终将变得更有道理(说了15年的家伙说……变得更容易了!)
Yes it is a lot of software to configure and build. 是的,它是许多用于配置和构建的软件。 pkg-config
can help a lot here! pkg-config
在这里可以提供很多帮助! When you see Package hdf5 was not found in the pkg-config search path
, that means you should adjust your PKG_CONFIG_DIR
to point to the location of the package-config files. 当您Package hdf5 was not found in the pkg-config search path
看到Package hdf5 was not found in the pkg-config search path
,这意味着您应该调整PKG_CONFIG_DIR
以指向软件包配置文件的位置。 Unfortunately, hdf5 doesn't provide a .pc (package-config) file, so you'll have to just do that part by hand. 不幸的是,hdf5没有提供.pc(package-config)文件,因此您只需要手工完成即可。 Oh, and netcdf doesn't provide a pkg-config either: it provides a script nc-config that netcdf-python will use. 哦,netcdf也不提供pkg-config:它提供了netcdf-python将使用的脚本nc-config。
Let me provide a concrete example: 让我提供一个具体的例子:
/home/robl/soft/mpich-master
MPICH-master安装在/home/robl/soft/mpich-master
/home/robl/soft/hdf5-1.8.16
HDF5安装在/home/robl/soft/hdf5-1.8.16
../../hdf5-1.8.16/configure --prefix=/home/robl/work/soft/hdf5-1.8.16 CC=/home/robl/work/soft/mpich/bin/mpicc --enable-parallel
例如配置如../../hdf5-1.8.16/configure --prefix=/home/robl/work/soft/hdf5-1.8.16 CC=/home/robl/work/soft/mpich/bin/mpicc --enable-parallel
/home/robl/soft/netcdf-master
NetCDF4安装在/home/robl/soft/netcdf-master
./configure CC=${HOME}/work/soft/mpich/bin/mpicc --prefix=${HOME}/work/soft/netcdf-master CPPFLAGS=-I${HOME}/work/soft/hdf5-1.8.16/include LDFLAGS=-L${HOME}/work/soft/hdf5-1.8.16/lib
例如,配置为./configure CC=${HOME}/work/soft/mpich/bin/mpicc --prefix=${HOME}/work/soft/netcdf-master CPPFLAGS=-I${HOME}/work/soft/hdf5-1.8.16/include LDFLAGS=-L${HOME}/work/soft/hdf5-1.8.16/lib
now you have all the pre-requisietes for netcdf-python 现在您已经具备了netcdf-python的所有前提条件
by the way, http://unidata.github.io/netcdf4-python/ lays out the prerequisites and the necessary configure options 顺便说一下, http: //unidata.github.io/netcdf4-python/列出了先决条件和必要的配置选项
Don't get hung up on the carping about hdf5.pc. 不要为hdf5.pc烦恼而烦恼。 If you have nc-config in your path, it will provide the needed information. 如果您的路径中有nc-config,它将提供所需的信息。
If you are building for parallel programming, set CC to your MPI compiler. 如果要进行并行编程,请将CC设置为MPI编译器。 if not, you can skip the ``export CC=...'' step: 如果没有,您可以跳过``export CC = ...''步骤:
cd netcdf-python
export CC=${HOME}/work/soft/mpich/bin/mpicc
export PATH=${HOME}/work/soft/netcdf-master/bin:${PATH}
python setup.py build
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.