fatal error C1083: Cannot open include file: 'hdf5.h': No such file or directory


I am trying to install a python package that requires HDF5 (h5py). I have installed HDF5 on Windows 10 using the installer. The installation seems to have been successful.

I still get the error: ’ Cannot open include file: ‘hdf5.h’: No such file or directory’ even though I can see the hdf5.h file in the Include directory.

Do you have any idea how I can resolve this issue and get the complier to find this file.

Many thanks.


[24/24] Cythonizing C:\Users\mjp321\AppData\Local\Temp\pip-install-p2d_lh9t\h5py_de07a0fdf0a04c709ef25b2c0e5226bd\h5py\utils.pyx
_ building ‘h5py.defs’ extension_
_ creating build\temp.win-amd64-cpython-311_
_ creating build\temp.win-amd64-cpython-311\Release_
_ creating build\temp.win-amd64-cpython-311\Release\Users_
_ creating build\temp.win-amd64-cpython-311\Release\Users\mjp321_
_ creating build\temp.win-amd64-cpython-311\Release\Users\mjp321\AppData_
_ creating build\temp.win-amd64-cpython-311\Release\Users\mjp321\AppData\Local_
_ creating build\temp.win-amd64-cpython-311\Release\Users\mjp321\AppData\Local\Temp_
_ creating build\temp.win-amd64-cpython-311\Release\Users\mjp321\AppData\Local\Temp\pip-install-p2d_lh9t_
_ creating build\temp.win-amd64-cpython-311\Release\Users\mjp321\AppData\Local\Temp\pip-install-p2d_lh9t\h5py_de07a0fdf0a04c709ef25b2c0e5226bd_
_ creating build\temp.win-amd64-cpython-311\Release\Users\mjp321\AppData\Local\Temp\pip-install-p2d_lh9t\h5py_de07a0fdf0a04c709ef25b2c0e5226bd\h5py_
_ “C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe” /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DH5_USE_18_API -DNPY_NO_DEPRECATED_API=0 -D_HDF5USEDLL_ -DH5_BUILT_AS_DYNAMIC_LIB -I.\h5py -IC:\Users\mjp321\AppData\Local\Temp\pip-install-p2d_lh9t\h5py_de07a0fdf0a04c709ef25b2c0e5226bd\lzf -IC:\Users\mjp321\AppData\Local\Temp\pip-install-p2d_lh9t\h5py_de07a0fdf0a04c709ef25b2c0e5226bd\lzf\lzf -IC:\Users\mjp321\AppData\Local\Temp\pip-install-p2d_lh9t\h5py_de07a0fdf0a04c709ef25b2c0e5226bd\windows -IC:\Users\mjp321\AppData\Local\Temp\pip-build-env-l9nbg_49\overlay\Lib\site-packages\numpy\core\include “-IC:\Users\mjp321\Documents\kd_package (1)\kd_package\kd_calculator\include” “-IC:\Program Files\Python311\include” “-IC:\Program Files\Python311\Include” “-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include” “-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\shared” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\winrt” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\cppwinrt” “-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um” /TcC:\Users\mjp321\AppData\Local\Temp\pip-install-p2d_lh9t\h5py_de07a0fdf0a04c709ef25b2c0e5226bd\h5py\defs.c /Fobuild\temp.win-amd64-cpython-311\Release\Users\mjp321\AppData\Local\Temp\pip-install-p2d_lh9t\h5py_de07a0fdf0a04c709ef25b2c0e5226bd\h5py\defs.obj_
_ defs.c_
_ C:\Users\mjp321\AppData\Local\Temp\pip-install-p2d_lh9t\h5py_de07a0fdf0a04c709ef25b2c0e5226bd\h5py\api_compat.h(27): fatal error C1083: Cannot open include file: ‘hdf5.h’: No such file or directory_
_ error: command ‘C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe’ failed with exit code 2_
_ [end of output]_

_ note: This error originates from a subprocess, and is likely not a problem with pip._
_ ERROR: Failed building wheel for h5py_
Failed to build h5py
ERROR: Could not build wheels for h5py, which is required to install pyproject.toml-based projects

Do you need to build h5py from source? Do you have any need for the HDF5 library outside of h5py?

With pip install h5py you get a version of the HDF5 library but cannot be used with other software.


@m.peach21 h5py 3.8 was released yesterday with support for Python 3.11 so pip install will just work.


A error occurs when I install hdf5-1.14 from source and h5py from pip. It’s as follow.

ERROR src/Tools/PyTools.h:176 (checkPyError) RuntimeError: Wrong file driver version # (wrong file driver version #)

Hi @coderwang119,

There is not enough information but if you just did pip install h5py then you likely installed two different versions of libhdf5 and h5py is finding first the wrong one, which is the 1.14 version. You do not need to install libhdf5 first yourself because h5py comes with its own. However, if you want to use any specific version of libhdf5 with h5py then you need to install it from source, see h5py documentation.


Yes, you are right!
Headers are 1.12.2, library is 1.14.0
Warning! HDF5 library release mismatched error

So how to find the place where the right library files (1.12.2) are? I have install it by pip, but the path of library files is need to build other programe.

If you want to use libhdf5 with other software not just h5py then follow the documentation link I included in my previous reply to install h5py with your 1.14.0 version. You will first need to uninstall the current h5py first.


Thanks for you suggestion! I have tryed it, but some errors about the wheels happened when I re-install the h5py with CC="mpicc" pip install --no-binary=h5py h5py,and the full outlog is below.
outlog.txt (11.7 KB)

Oh, yes, my environment variables are set as follows.


export PATH=${INSTALL_DIR}/hdf5-1.14:${INSTALL_DIR}/hdf5-1.14/bin:${INSTALL_DIR}/hdf5-1.14/include:${PATH}
export LD_LIBRARY_PATH=${INSTALL_DIR}/hdf5-1.14/lib:${INSTALL_DIR}/hdf5-1.14/lib64:${LD_LIBRARY_PATH}
export HDF5_MPI=ON
export HDF5_DIR=${INSTALL_DIR}/hdf5-1.14
export HDF5_ROOT_DIR=${INSTALL_DIR}/hdf5-1.14
export HDF5_INCLUDEDIR=${INSTALL_DIR}/hdf5-1.14/include
export HDF5_LIBRARY=${INSTALL_DIR}/hdf5-1.14/lib:${INSTALL_DIR}/hdf5-1.14/lib64:${LD_LIBRARY_PATH}

The error message almost at the end of the build log you included explains the problem:

ValueError: Specify only one of: HDF5 lib/include dirs, HDF5 prefix dir, or HDF5 pkgconfig name

You have too many HDF5_... env. variables. You only need HDF5_MPI, HDF5_DIR, and, perhaps, HDF5_DISABLE_VERSION_CHECK. And these can be on the pip command-line because they are only needed for h5py install.

Since you are building for MPI, this h5py issue may provide useful information if you still encounter install problems: https://github.com/h5py/h5py/issues/2222.