pythonnumpyanacondaconda

ImportError when importing NumPy – missing libgfortran.5.dylib on macOS (VS Code, Jupyter, Conda)


I’m working on macOS Sequoia 15.4, using VS Code and Jupyter Notebooks with Conda environments.

Everything worked fine until yesterday. Now, when I try to run any of my existing environments, importing NumPy or other scientific libraries results in the following ImportError related to libgfortran.5.dylib.

ImportError: dlopen(..._multiarray_umath.cpython-39-darwin.so): 
Library not loaded: @rpath/libgfortran.5.dylib
  Referenced from: /Users/.../miniconda3/envs/PARESIS/lib/libopenblasp-r0.3.21.dylib
  Reason: tried: '/Users/.../libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'),
  '/usr/local/lib/libgfortran.5.dylib' (no such file),
  '/usr/lib/libgfortran.5.dylib' (no such file, not in dyld cache)

This ends with:

ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.

This happens only in older environments. If I create a new Conda environment, everything works fine.

I tried reinstalling NumPy using

conda install numpy --force-reinstall

, and also explicitly installing libgfortran=5 in the affected environment. I also updated Conda, restarted my system, and relaunched VS Code multiple times.

I expected NumPy to be reinstalled correctly and the missing library issue to be resolved, but the error persists. I was hoping to avoid recreating all my environments from scratch since I have a lot of dependencies already configured.


Solution

  • As mentioned previously, this is similar to this question.

    MacOS Sequoia 15.4.1 update raises an error for duplicate R paths, which triggers the error you mentioned for typically 'old' environments.

    If you don't want to re-create an environment, you can try to install libgfortran5 package to its version which avoids the error (>=14), e.g. run this command with your environment activated:

    conda install "libgfortran5>=14"
    

    It should fix the error without having to reinstall everything, assuming the version is compatible with other dependancies and that it's the only one causing the error.