python native_crash ai_generated true

Segmentation fault (core dumped)

ID: python/segfault-numpy-import

Also available as: JSON · Markdown
76%Fix Rate
72%Confidence
34Evidence
2021-09-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
311 active — — —

Root Cause

The segfault is caused by numpy's bundled OpenBLAS failing to detect the correct ARM CPU core type at runtime. Setting the OPENBLAS_CORETYPE environment variable or switching to conda-forge's numpy (which ships with a properly configured OpenBLAS for ARM) resolves the issue in most cases.

generic

Workarounds

  1. 84% success Set OPENBLAS_CORETYPE environment variable before import
    Export OPENBLAS_CORETYPE=ARMV8 (or CORTEXA72, CORTEXA53, etc. depending on your CPU) before running Python. Add to shell profile: 'export OPENBLAS_CORETYPE=ARMV8'. This overrides the faulty auto-detection and forces OpenBLAS to use a safe, compatible code path.

    Sources: https://github.com/OpenMathLib/OpenBLAS/wiki/Faq#what-is-openblas_coretype

  2. 89% success Install numpy via conda-forge
    Use 'conda install -c conda-forge numpy' or 'mamba install -c conda-forge numpy'. Conda-forge builds numpy with OpenBLAS configured specifically for the target architecture and includes proper ARM detection.

    Sources: https://conda-forge.org/

  3. 71% success Build numpy from source with system BLAS
    Install system OpenBLAS ('apt install libopenblas-dev') then 'pip install numpy --no-binary numpy'. This compiles numpy against the system's properly configured BLAS rather than the bundled one.

    Sources: https://numpy.org/doc/stable/building/

Dead Ends

Common approaches that don't work:

  1. Reinstalling numpy with 'pip install --force-reinstall numpy' 93% fail

    The crash is not caused by a corrupt installation. It is caused by the OpenBLAS library bundled inside the numpy wheel failing to auto-detect the ARM CPU microarchitecture. Reinstalling downloads the same binary wheel with the same broken auto-detection.

  2. Upgrading pip and setuptools 97% fail

    The segfault occurs inside numpy's compiled C/Fortran code (OpenBLAS), which has no dependency on pip or setuptools at runtime. Upgrading build tools has zero effect on the runtime behavior of already-compiled shared objects.

  3. Downgrading numpy to an older version 72% fail

    Older numpy versions have the same or worse ARM support. The OpenBLAS auto-detection issue has been present across multiple numpy versions. Older versions are more likely to lack arm64 wheel support entirely, forcing a slow source build that may also fail.

Error Chain

Frequently confused with: