AttributeError: module 'h5py' has no attribute 'File'

I have configured a parallel version of hdf5 on my WSL2 Ubuntu 22.04 on Windows 11 system.
In C and Fortran, parallel hdf5 works quite well. However, things get muddy when I’m following this guide to install parallel h5py , and trying to run the demo code. The system continues to complain AttributeError: module ‘h5py’ has no attribute ‘File’.

I searched for several cases on StackExchange but none of those seem to work. I installed mpi4py and h5py simply by pip3, so there is nothing to do with conda error. It’s highly appreciated if anyone can give some suggestions.

Hi @yeyuchen,

That AttributeError usually is caused by a bad installation of h5py. Can you provide exact commands you used to install libhdf5, h5py? You mention “conda error”. Did you install the parallel version of libhdf5 via the conda package manager?

Take care,

Hi @ajelenak ,

Thanks for your reply. Below is the command I used for install hdf5 and h5py:

 ./configure --prefix=/usr/local --enable-parallel --enable-fortran --enable-shared
 export CC=mpicc
 export HDF5_MPI="ON"
 export HDF5_DIR="/usr/local"
 pip3 install --no-binary=h5py h5py

There is nothing to do with conda. This is just a solution come from here and I’m not in this case.


The install commands look okay. I assume the output from that pip3 command is not available now?

One useful check would be to verify what is actually installed as h5py. You should have an h5py directory under the site-packages directory. To find out the location of the site packages directory, run this command:

python -c "import site; print(site.getsitepackages())"

In the h5py directory, there should be a _hl one, and in it a file. The AttributeError you reported indicates that this file is missing in your installation.

Take care,

Errors like this can often occur if you’ve got a file called in the same directory where you’re running the code - import h5py will find this file instead of your h5py installation.

1 Like