Installing h5py

h5py is a python module which allow you to easily use the HDF5 format from python. HDF5 is a powerful format which supports compression and parallel I/O. Installing h5py from source was not a piece of cake. I show here the easy and fast way. As a souvenir, I also show the manual way, which is to be avoided.

The easy way

Use pip, a package manager for python ! The issues mentioned below (i.e a custom MPI path) can be solved with :

If you have HDF5 in a non-standard location, for example in /HDF5_folder, use instead:

To install HDF5, see this post.

The painful way

Okay, let’s download the source for h5py and compile it. HDF5 is already installed so it should be easy as python install, right ?

It cannot find the MPI header files. No problem, we just need to update the compiler include flags. Turns out, it is not so easy:

After searching 10min on the Internet, I finally find it:

Some compilation later, the module fails to link:

Now, what does this even mean ?? After looking into the installation folder, I realize only the static libraries have been installed from HDF5. Let’s try to reinstall HDF5 both shared and static libraries. This should solve the issue:

It is a very bad idea, the compiler spurts a lot of not-so-nice messages at me. Now, let’s try to install only the shared version of HDF5:

It compiles ! Now, we just remove the old files and install HDF5 properly. Even better, h5py is happy this thime and install itself properly with:

Finally, we can try loading the module in python:

The library is not found so let us add it to the proper variable:

And now it works ! It was not that straightforward though.

Other possible error

Installing it on a Fedora machine, I got:

It happens when you try to import h5py from the source directory. Change to another directory and try again.