I needed a 64-bit version of HDF5 and NetCDF4, here’s how you get that going on Mac OS X 10.6. Download the and uncompress the static HDF5 1.8.6 binaries. Download the and uncompress the NetCDF 4.1.2 source. Get rid of all of the.la files in the HDF5 libs folder. From the command line, set the following environmental variables. HDF5 is a great mechanism for storing large numerical arrays of homogenous type, for data models that can be organized hierarchically and benefit from tagging of datasets with arbitrary metadata. It’s quite different from SQL-style relational databases.
From charlesreid1
- 1Installing
- 2Using
Mac OS X Lion: Use Brew
If you're on Mac OS X Lion (10.7), you may run into issues. If you're less inclined to get elbow-deep in computer problems, you can just use Homebrew (http://mxcl.github.io/homebrew/), a really nice package manager for Mac OS X. MacPorts and Fink can both be nightmares, but Homebrew manages to do everything hassle-free.
You can install HDF5 using Homebrew by running:
UPDATE: HDF5 has since moved to Homebrew-Science (https://github.com/Homebrew/homebrew-science). You can 'tap' into Homebrew Science to get to the HDF5 recipe.
Configuring
I am using the HDF5 libraries for various software tools available through the CRSim Software repository http://software.crsim.utah.edu/ - specifically, C++ programs using the C++ interface to HDF5 - necessitating the --enable-cxx
configure argument:
You can optionally use the configure arguments --enable-static-exe --enable-static
, though in my experience these aren't necessary to build (and link to) HDF5.
Errors
You may run into problems during make check, something looking like this:
The solution, as mentioned here http://kartadikaria.wordpress.com/2011/10/06/how-to-install-hdf5-macintosh-lion/, is to modify the configure flags for GNU compilers (the one used on Mac, if you're using gcc). Change the PROD_CFLAG
for gcc compilers version 4 and up to use -O0
instead of the default -O3
.
Python and HDF5
Link to docs: http://docs.h5py.org/en/latest/
Link to quickstart: http://docs.h5py.org/en/latest/quick.html
Start by creating an HDF5 file object:
Now that you have a file object, create data sets:
(This is not a file, but a dataset object - this is similar to a Numpy array.)
HDF5 files are stored in a hierarchical way, with a 'directory'-like structure.
The file object is the root group, equivalent to /
on a Unix system:
Hdf5 For Mac Download
It is highly recommended that you use a pre-built version of h5py, either from aPython Distribution, an OS-specific package manager, or a pre-built wheel fromPyPI.
Be aware however that most pre-built versions lack MPI support, and that theyare built against a specific version of HDF5. If you require MPI support, ornewer HDF5 features, you will need to build from source.
After installing h5py, you should run the tests to be sure that everything wasinstalled correctly. This can be done in the python interpreter via:
Pre-built installation (recommended)¶
Pre-build h5py can be installed via many Python Distributions, OS-specificpackage managers, or via h5py wheels.
Python Distributions¶
If you do not already use a Python Distribution, we recommend eitherAnaconda/MinicondaorEnthought Canopy, both of whichsupport most versions of Microsoft Windows, OSX/MacOS, and a variety of LinuxDistributions. Installation of h5py can be done on the command line via:
for Anaconda/MiniConda, and via:
for Canopy.
Wheels¶
If you have an existing Python installation (e.g. a python.org download,or one that comes with your OS), then on Windows, MacOS/OSX, andLinux on Intel computers, pre-built h5py wheels can be installed via pip fromPyPI:
Additionally, for Windows users, Chris Gohlke provides third-party wheelswhich use Intel’s MKL.
OS-Specific Package Managers¶
On OSX/MacOS, h5py can be installed via Homebrew,Macports, or Fink.
The current state of h5py in various Linux Distributions can be seen athttps://pkgs.org/download/python-h5py, and can be installed via the packagemanager.
As far as the h5py developers know, none of the Windows package managers (e.g.Chocolatey, nuget)have h5py included, however they may assist in installing h5py’s requirementswhen building from source.
Source installation¶
To install h5py from source, you need three things installed:
- A supported Python version with development headers
- Cython >=0.29
- HDF5 1.8.4 or newer with development headers
- A C compiler
On Unix platforms, you also need pkg-config
unless you explicitly specifya path for HDF5 as described in Custom installation.
OS-specific instructions for installing HDF5, Python and a C compiler are in the next fewsections.
Additional Python-level requirements should be installed automatically (whichwill require an internet connection).
The actual installation of h5py should be done via:
or, from a tarball or git checkout
If you are working on a development version and the underlying cython files changeit may be necessary to force a full rebuild. The easiest way to achieve this is
from the top of your clone and then rebuilding.
Source installation on OSX/MacOS¶
HDF5 and Python are most likely in your package manager (e.g. Homebrew,Macports, or Fink).Be sure to install the development headers, as sometimes they are not includedin the main package.
XCode comes with a C compiler (clang), and your package manager will likely haveother C compilers for you to install.
Source installation on Linux/Other Unix¶
HDF5 and Python are most likely in your package manager. A C compiler almostdefinitely is, usually there is some kind of metapackage to install thedefault build tools, e.g. build-essential, which should be sufficient for ourneeds. Make sure that that you have the development headers, as they areusually not installed by default. They can usually be found in python-dev
orsimilar and libhdf5-dev
or similar.
Source installation on Windows¶
Installing from source on Windows is a much more difficult prospect thaninstalling from source on other OSs, as not only are you likely to need tocompile HDF5 from source, everything must be built with the correct version ofVisual Studio. Additional patches are also needed to HDF5 to get HDF5 and Pythonto work together.
We recommend examining the appveyor build scripts, and using those to build andinstall HDF5 and h5py.
Hdf5 For Mac Os
Custom installation¶
Important
Remember that pip installs wheels by default.To perform a custom installation with pip, you should use:
or build from a git checkout or downloaded tarball to avoid gettinga pre-built version of h5py.
You can specify build options for h5py as environment variables when you buildit from source:
Hdf5 Macports
The supported build options are:
- To specify where to find HDF5, use one of these options:
HDF5_LIBDIR
andHDF5_INCLUDEDIR
: the directory containing thecompiled HDF5 libraries and the directory containing the C header files,respectively.HDF5_DIR
: a shortcut for common installations, a directory withlib
andinclude
subdirectories containing compiled libraries and C headers.HDF5_PKGCONFIG_NAME
: A name to querypkg-config
for.If none of these options are specified, h5py will querypkg-config
bydefault forhdf5
, orhdf5-openmpi
if building with MPI support.
HDF5_MPI=ON
to build with MPI integration - see Building against Parallel HDF5.HDF5_VERSION
to force a specified HDF5 version. In most cases, you don’tneed to set this; the version number will be detected from the HDF5 library.H5PY_SYSTEM_LZF=1
to build the bundled LZF compression filter(see Filter pipeline) against an external LZF library, rather thanusing the bundled LZF C code.
Building against Parallel HDF5¶
Hdf5 For Mac Software
If you just want to build with mpicc
, and don’t care about using ParallelHDF5 features in h5py itself:
If you want access to the full Parallel HDF5 feature set in h5py(Parallel HDF5), you will further have to build in MPI mode. This can be doneby setting the HDF5_MPI
environment variable:
You will need a shared-library build of Parallel HDF5 as well, i.e. built with./configure--enable-shared--enable-parallel
.