TensorFlow import error with NumPy 2: _ARRAY_API not found (tested)

import tensorflow fails with A module that was compiled using NumPy 1.x cannot be run in NumPy 2, AttributeError: _ARRAY_API not found and finally ImportError: numpy.core.umath failed to import. TensorFlow 2.17 and older were built for NumPy 1.x; install numpy<2 or upgrade TensorFlow. Reproduced and both fixes tested below.

1. Reproduce: TensorFlow 2.15 with NumPy 2

b1.py imports numpy and TensorFlow and does one tensor op. The venv has tensorflow-cpu 2.15.1 (which requires numpy<2.0.0) and numpy 2.2.6 installed after it, the way another package's upgrade often pulls it in:

import numpy
print("numpy", numpy.__version__)
import tensorflow as tf
print("tensorflow", tf.__version__)
print(tf.constant([1.0, 2.0]).numpy().sum())

The full output is 127 lines of repeated tracebacks; these are its message lines:

$ pip install "numpy==2.2.6"   # e.g. pulled in by another package
$ python b1.py 2>&1 | grep -E "...messages..."
numpy 2.2.6
A module that was compiled using NumPy 1.x cannot be run in
AttributeError: _ARRAY_API not found
A module that was compiled using NumPy 1.x cannot be run in
AttributeError: _ARRAY_API not found
A module that was compiled using NumPy 1.x cannot be run in
AttributeError: _ARRAY_API not found
ImportError: numpy.core._multiarray_umath failed to import
ImportError: numpy.core.umath failed to import
exit status: 1

2. What it means

3. Fix: downgrade numpy, or upgrade TensorFlow

Option A: keep the old TensorFlow and pin numpy<2:

$ pip check
The package `tensorflow-cpu` requires `numpy>=1.23.5,<2.0.0`, but `2.2.6` is installed
$ pip install "numpy<2"
$ python b1.py
numpy 1.26.4
tensorflow 2.15.1
3.0

Option B: upgrade TensorFlow. With tensorflow-cpu 2.21.0 the same script runs on numpy 2.5.4 (Python 3.13.5):

$ pip install -U tensorflow   # tested: 2.21.0
$ python b1.py
numpy 2.5.4
tensorflow 2.21.0
3.0

Upgrading past 2.15 also moves you to Keras 3, which breaks some old imports: see TensorFlow Keras errors after Keras 3. Same NumPy error with pandas: pandas "_ARRAY_API not found". Other NumPy 2 changes: NumPy 2 breaking changes. Can't install TensorFlow at all: No matching distribution found.

Frequently asked questions

Why does import tensorflow say _ARRAY_API not found?

The installed TensorFlow (2.17 or older) was compiled against NumPy 1.x, and NumPy 2 is installed. Its PyPI metadata requires numpy<2.0.0.

How do I fix numpy.core.umath failed to import in TensorFlow?

pip install "numpy<2" to match the old TensorFlow, or upgrade TensorFlow to 2.18 or newer, which supports NumPy 2.

Which TensorFlow version supports NumPy 2?

2.18.0 is the first whose PyPI metadata allows NumPy 2; 2.21.0 ran with numpy 2.5.4 in this test.

Written with AI assistance. Measured on 2026-10-24 on Linux: tensorflow-cpu 2.15.1 on Python 3.11.17 with numpy 2.2.6 and 1.26.4, and tensorflow-cpu 2.21.0 with numpy 2.5.4 on Python 3.13.5; TensorFlow numpy pins read from the PyPI JSON API. Output filtered to message lines as shown. PlainTables is our extension; TensorFlow and NumPy are free.