MSS icon indicating copy to clipboard operation
MSS copied to clipboard

Importing the numpy C-extensions failed.

Open ReimarBauer opened this issue 8 months ago • 2 comments

sometimes I get in this problem. The workaround is to rebuild the env.

% msui
Traceback (most recent call last):
  File "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/_core/__init__.py", line 23, in <module>
    from . import multiarray
  File "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/_core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/_core/overrides.py", line 7, in <module>
    from numpy._core._multiarray_umath import (
ImportError: dlopen(/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-darwin.so, 0x0002): Library not loaded: @rpath/libgfortran.5.dylib
  Referenced from: <C435405B-BFF1-399F-A1EC-BD43418F546A> /Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/libopenblas.0.dylib
  Reason: tried: '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/_core/../../../../libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/_core/../../../../libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/bin/../lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/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:

Traceback (most recent call last):
  File "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/__init__.py", line 114, in <module>
    from numpy.__config__ import show_config
  File "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/__config__.py", line 4, in <module>
    from numpy._core._multiarray_umath import (
  File "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/_core/__init__.py", line 49, in <module>
    raise ImportError(msg)
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.11 from "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/bin/python3.11"
  * The NumPy version is: "2.2.3"

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

Original error was: dlopen(/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-darwin.so, 0x0002): Library not loaded: @rpath/libgfortran.5.dylib
  Referenced from: <C435405B-BFF1-399F-A1EC-BD43418F546A> /Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/libopenblas.0.dylib
  Reason: tried: '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/_core/../../../../libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/_core/../../../../libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/bin/../lib/libgfortran.5.dylib' (duplicate LC_RPATH '@loader_path'), '/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/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:

Traceback (most recent call last):
  File "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/bin/msui", line 4, in <module>
    from mslib.msui.msui import main
  File "/Users/reimarbauer/MAIN/MSS/mslib/msui/msui.py", line 41, in <module>
    from mslib.msui.msui_mainwindow import MSUIMainWindow
  File "/Users/reimarbauer/MAIN/MSS/mslib/msui/msui_mainwindow.py", line 46, in <module>
    from mslib.msui import flighttrack as ft
  File "/Users/reimarbauer/MAIN/MSS/mslib/msui/flighttrack.py", line 49, in <module>
    from mslib.utils.units import units
  File "/Users/reimarbauer/MAIN/MSS/mslib/utils/units.py", line 31, in <module>
    from metpy.units import units, check_units  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/metpy/__init__.py", line 13, in <module>
    from .xarray import *  # noqa: F401, F403, E402
    ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/metpy/xarray.py", line 25, in <module>
    import numpy as np
  File "/Users/reimarbauer/MAIN/MSS/.pixi/envs/dev/lib/python3.11/site-packages/numpy/__init__.py", line 119, in <module>
    raise ImportError(msg) from e
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.

ReimarBauer avatar May 13 '25 10:05 ReimarBauer

pytest -k test_main_version_flag
ImportError while loading conftest '/Users/reimarbauer/MAIN/MSS/conftest.py'.
conftest.py:38: in <module>
    from mslib.mswms.demodata import DataFiles
mslib/mswms/demodata.py:32: in <module>
    import netCDF4 as nc
.pixi/envs/dev/lib/python3.11/site-packages/netCDF4/__init__.py:3: in <module>
    from ._netCDF4 import *
src/netCDF4/_netCDF4.pyx:1: in init netCDF4._netCDF4
    ???
.pixi/envs/dev/lib/python3.11/site-packages/numpy/__init__.py:119: in <module>
    raise ImportError(msg) from e
E   ImportError: Error importing numpy: you should not try to import numpy from
E           its source directory; please exit the numpy source tree, and relaunch
E           your python interpreter from there.

workaround

pixi remove netcdf4
pixi add netcdf4

ReimarBauer avatar May 14 '25 12:05 ReimarBauer

https://github.com/conda-forge/netcdf4-feedstock/issues/172

ReimarBauer avatar May 14 '25 15:05 ReimarBauer