Search code examples
pythonhomebrewhdf5h5py

HDF5 makes a problem after brew update & upgrade


I'm M1 user and coding on python 3.9.10 up to now.

I try updating lib. with homebrew, especially for python 3.9.12 and HDF5. Also I reinstalled h5py. Here I tried.

brew update & upgrade
brew reinstall hdf5
export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.13.0/
pip install h5py --upgrade --no-dependencies --force

All upgrade was done. However, I met such an error message when I tried codes, which has no error based on previous build environments.

>     import h5py
>  File "/opt/homebrew/lib/python3.9/site-packages/h5py/__init__.py", line 25, in  <module>
>    from . import _errors
> ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/h5py/_errors.cpython-39- darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/hdf5/lib/libhdf5.300.dylib
>  Referenced from: /opt/homebrew/lib/python3.9/site-packages/h5py/_errors.cpython-39-darwin.so
>  Reason: tried: '/opt/homebrew/opt/hdf5/lib/libhdf5.300.dylib' (no such file), '/usr/local/lib/libhdf5.300.dylib' (no such file), '/usr/lib/libhdf5.300.dylib' (no such file), '/opt/homebrew/Cellar/hdf5/1.12.1_1/lib/libhdf5.300.dylib' (no such file), '/usr/local/lib/libhdf5.300.dylib' (no such file), '/usr/lib/libhdf5.300.dylib' (no such file)

As shown above, hdf5_dir is fixed on 1.12.1_1 after brew upgrade, even I already installed 1.13.0 which didn't make a problem until trying brew upgrade. Please, help me if anyone know what makes the problem and how to solve it.

Thanks in advance.


Solution

  • The following worked for me. First, uninstall h5py and hdf5 (also deleted my pip cache, but not sure how relevant this is). Then just run

    > brew install hdf5
    > export HDF5_DIR="$(brew --prefix hdf5)"
    > pip install --no-binary=h5py h5py