A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0
A compiled package in your environment was built against NumPy 1 and your NumPy is 2. Upgrade the affected package to a NumPy-2-compatible release, or pin numpy below 2 as a stopgap.
Updated
The error
A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.0 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.
Depending on the module, an ImportError, AttributeError: _ARRAY_API not found, or PyTorch's terse variant follows:
RuntimeError: Numpy is not available
What it means
Packages with compiled extensions — torch, old scipy builds, opencv, many others — link against NumPy's binary interface (ABI): the memory layout NumPy promises to C code. NumPy 2.0 (June 2024) changed that interface. A package compiled against NumPy 1 makes assumptions that NumPy 2 no longer honours, so importing it under NumPy 2 is refused rather than allowed to crash or corrupt.
The message names the offending module in the traceback right below it — read that part; it tells you which package to fix.
Why it happens
pip install of something modern pulled in numpy>=2, while an older compiled package in the same environment predates it. Environments created before mid-2024 and upgraded piecemeal are the natural habitat. The reverse also occurs: a package built against NumPy 2 needs NumPy ≥2 to run — pinning numpy<2 while installing current wheels creates the mirror-image failure.
How to fix it
1. Upgrade the module the traceback names. Every major package shipped NumPy-2-compatible builds — packages compiled against NumPy 2 run on both 1.x and 2.x:
pip install -U torch opencv-python scipyThen confirm:
import numpy; print(numpy.__version__)
import torch; print(torch.__version__) # or whichever module complained2. If the offender cannot be upgraded, pin NumPy below 2.
pip install "numpy<2"Legitimate for frozen projects and abandoned dependencies — but it quietly blocks you from current releases of everything else, so mark it as debt.
3. For your own compiled extensions, rebuild against NumPy 2. Building with numpy>=2 (and pybind11>=2.12 where used) produces binaries compatible with both major versions — build once, run anywhere.
4. In messy environments, resolve wholesale rather than piecemeal. Fresh venv, one pip install -r requirements.txt with current ranges — the combination that co-installs today is easier to reach from zero than by nudging an old environment.
How to prevent it
Upgrade the compiled cluster together — numpy, torch, scipy, opencv are one unit in practice. When NumPy makes a major release, expect a transition window and hold back the numpy upgrade in production until your stack's wheels caught up (a lock file makes that a one-line decision).
Related errors
- module 'numpy' has no attribute 'float' — the source-level NumPy break, same era
- operator torchvision::nms does not exist — ABI mismatch between torch and torchvision
- ResolutionImpossible: conflicting dependencies
- 'super' object has no attribute 'sklearn_tags'