[Python] import numpy failed after upgrading MacOS to 15.4

Discussão em 'Python' iniciado por Stack, Abril 3, 2025.

  1. Stack

    Stack Membro Participativo

    After upgrading MacOS to 15.4. the import failed: Exception has occurred: 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.

    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.
    ImportError: dlopen(/opt/miniconda3/envs/ho/lib/python3.12/site-packages/numpy/_core/_multiarray_umath.cpython-312-darwin.so, 0x0002): Library not loaded: @rpath/libgfortran.5.dylib
    Referenced from: <0B9C315B-A1DD-3527-88DB-4B90531D343F> /opt/miniconda3/envs/ho/lib/libopenblas.0.dylib
    Reason: tried: '/opt/miniconda3/envs/ho/lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/opt/miniconda3/envs/ho/lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/opt/miniconda3/envs/ho/lib/python3.12/site-packages/numpy/_core/../../../../libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/opt/miniconda3/envs/ho/lib/python3.12/site-packages/numpy/_core/../../../../libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/opt/miniconda3/envs/ho/bin/../lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/opt/miniconda3/envs/ho/bin/../lib/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)

    During handling of the above exception, another exception occurred:

    ImportError:

    IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

    Importing the numpy C-extensions failed. This error can happen for
    many reasons, often due to issues with your setup or how NumPy was
    installed.

    We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

    Please note and check the following:

    * The Python version is: Python3.12 from "/opt/miniconda3/envs/ho/bin/python"
    * The NumPy version is: "2.0.0"

    and make sure that they are the versions you expect.
    Please carefully study the documentation linked above for further help.

    Original error was: dlopen(/opt/miniconda3/envs/ho/lib/python3.12/site-packages/numpy/_core/_multiarray_umath.cpython-312-darwin.so, 0x0002): Library not loaded: @rpath/libgfortran.5.dylib
    Referenced from: <0B9C315B-A1DD-3527-88DB-4B90531D343F> /opt/miniconda3/envs/ho/lib/libopenblas.0.dylib
    Reason: tried: '/opt/miniconda3/envs/ho/lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/opt/miniconda3/envs/ho/lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/opt/miniconda3/envs/ho/lib/python3.12/site-packages/numpy/_core/../../../../libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/opt/miniconda3/envs/ho/lib/python3.12/site-packages/numpy/_core/../../../../libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/opt/miniconda3/envs/ho/bin/../lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/opt/miniconda3/envs/ho/bin/../lib/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)


    The above exception was the direct cause of the following exception:

    File "/Users/yf/Library/CloudStorage/OneDrive-Personal/Documents/Projects/hohoho/playground.py", line 1, in <module>
    import numpy as np
    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.


    Everything was OK yesterday. The environment is created by miniconda. Python is 3.12.4, numpy is 2.0.0

    I tried all ways below, but cannot solve the exception:

    1. Delete and recreate the environment, install the same package backup in yaml file before.
    2. Clean all conda cache, reinstall miniconda, recreate the environment, reinstall the packages.
    3. search and delete the numpy path in the sys.path before import: sys.path = [p for p in sys.path if not os.path.basename(p).lower() == "numpy"]
    4. Clone a new environment, upgrade all packages the latest version.
    5. I have a packed .app file created by the pyinstaller before, which worked well before upgrading the OS, but cannot run now and report the same error.
    6. Another Mac also installed the .app before, but cannot run after upgrading the OS.

    Any other way I can solve the problem please..

    More details:

    1. previously OS version is 15.3
    2. Macbook Pro M1
    3. upgrade to NumPy 2.2.4 but not solve the problem:numpy 2.0.0-py312hb544834_0 --> 2.2.4-py312h7c1f314_0
    4. no gfortran in conda list
    5. another Macbook Air M1, which works fine with the pyinstaller build .app, and not any other python environment outside the .app, raise the same error after upgrade OS to 15.4

    Continue reading...

Compartilhe esta Página