import sklearn: _ARRAY_API not found with NumPy 2 (tested)

import sklearn under NumPy 2 can fail with AttributeError: _ARRAY_API not found and ImportError: numpy.core.multiarray failed to import. With scikit-learn 1.3.2 the module that actually breaks is SciPy 1.11.4. Pin numpy<2 or upgrade both; tested below.

1. Reproduce: scikit-learn 1.3.2 with NumPy 2

A Python 3.11 venv with scikit-learn==1.3.2 and scipy==1.11.4, then numpy==2.2.6 installed afterwards (installing all three in one command is refused by the resolver, because scikit-learn 1.3.2 requires numpy<2.0). b1.py:

import numpy
print("numpy", numpy.__version__)
import sklearn
print("sklearn", sklearn.__version__)
from sklearn.linear_model import LinearRegression
print(LinearRegression().fit([[0], [1]], [0, 2]).coef_)

Output (paths shortened to /venv and /usr):

numpy 2.2.6
/venv/lib/python3.11/site-packages/scipy/__init__.py:132: UserWarning: A NumPy version >=1.21.6 and <1.28.0 is required for this version of SciPy (detected version 2.2.6)
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.2.6 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'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "b1.py", line 3, in <module>
    import sklearn
  File "/venv/lib/python3.11/site-packages/sklearn/__init__.py", line 83, in <module>
    from .base import clone
  File "/venv/lib/python3.11/site-packages/sklearn/base.py", line 19, in <module>
    from .utils import _IS_32BIT
  File "/venv/lib/python3.11/site-packages/sklearn/utils/__init__.py", line 15, in <module>
    from scipy.sparse import issparse
  File "/venv/lib/python3.11/site-packages/scipy/sparse/__init__.py", line 274, in <module>
    from ._csr import *
  File "/venv/lib/python3.11/site-packages/scipy/sparse/_csr.py", line 11, in <module>
    from ._sparsetools import (csr_tocsc, csr_tobsr, csr_count_blocks,
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
  File "b1.py", line 3, in <module>
    import sklearn
  File "/venv/lib/python3.11/site-packages/sklearn/__init__.py", line 83, in <module>
    from .base import clone
  File "/venv/lib/python3.11/site-packages/sklearn/base.py", line 19, in <module>
    from .utils import _IS_32BIT
  File "/venv/lib/python3.11/site-packages/sklearn/utils/__init__.py", line 15, in <module>
    from scipy.sparse import issparse
  File "/venv/lib/python3.11/site-packages/scipy/sparse/__init__.py", line 274, in <module>
    from ._csr import *
  File "/venv/lib/python3.11/site-packages/scipy/sparse/_csr.py", line 11, in <module>
    from ._sparsetools import (csr_tocsc, csr_tobsr, csr_count_blocks,
ImportError: numpy.core.multiarray failed to import
exit status: 1
$ pip check
The package `scipy` requires `numpy>=1.21.6,<1.28.0`, but `2.2.6` is installed
The package `scikit-learn` requires `numpy>=1.17.3,<2.0`, but `2.2.6` is installed

2. What it means

3. Fix: pin numpy<2, or upgrade scikit-learn and SciPy together

$ pip install "numpy<2"
$ python b1.py
numpy 1.26.4
sklearn 1.3.2
[2.]
$ pip install -U scikit-learn scipy numpy
$ python b1.py
numpy 2.4.6
sklearn 1.9.1
[2.]

Upgrade SciPy along with scikit-learn: upgrading only scikit-learn can leave the old SciPy in place (SciPy 1.13.0 is the first that allows NumPy 2; see SciPy NumPy 2 compatibility). Same banner with other packages: A module compiled using NumPy 1.x, OpenCV, TensorFlow, pandas. All NumPy 2 changes: NumPy 2 breaking changes.

Frequently asked questions

Why does import sklearn fail with _ARRAY_API not found?

An old scikit-learn/SciPy built for NumPy 1.x is installed alongside NumPy 2; in this test the import broke inside scipy.sparse.

How do I fix it?

pip install "numpy<2", or pip install -U scikit-learn scipy numpy (scikit-learn 1.9.1 ran on numpy 2.4.6 here).

Written with AI assistance. Measured on 2026-10-24 on Linux with Python 3.11.17: scikit-learn 1.3.2 + scipy 1.11.4 with numpy 2.2.6 and 1.26.4, then upgraded to scikit-learn 1.9.1 with numpy 2.4.6. The script ran verbatim and the output was pasted unedited (paths shortened). PlainTables is our extension; scikit-learn, SciPy and NumPy are free.