"A module that was compiled using NumPy 1.x cannot be run in NumPy 2" (tested)
A module that was compiled using NumPy 1.x cannot be run in NumPy 2.x as it may crash means a compiled package you import was built for NumPy 1 and NumPy 2 is installed. The stack under it names that package. Reproduced with torch 2.2.2 and fixed both ways below.
1. Reproduce it with an old torch
b1.py imports numpy and torch, does a tensor op, then converts to a NumPy array. The venv has torch 2.2.2 (built against NumPy 1.x) and numpy 2.2.6, on Python 3.11:
import numpy
print("numpy", numpy.__version__)
import torch
print("torch", torch.__version__)
t = torch.tensor([1.0, 2.0])
print("tensor ops:", t.sum().item())
print(t.numpy())
Output (venv path shortened to /venv):
numpy 2.2.6
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 torch
File "/venv/lib/python3.11/site-packages/torch/__init__.py", line 1477, in <module>
from .functional import * # noqa: F403
File "/venv/lib/python3.11/site-packages/torch/functional.py", line 9, in <module>
import torch.nn.functional as F
File "/venv/lib/python3.11/site-packages/torch/nn/__init__.py", line 1, in <module>
from .modules import * # noqa: F403
File "/venv/lib/python3.11/site-packages/torch/nn/modules/__init__.py", line 35, in <module>
from .transformer import TransformerEncoder, TransformerDecoder, \
File "/venv/lib/python3.11/site-packages/torch/nn/modules/transformer.py", line 20, in <module>
device: torch.device = torch.device(torch._C._get_default_device()), # torch.device('cpu'),
/venv/lib/python3.11/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:84.)
device: torch.device = torch.device(torch._C._get_default_device()), # torch.device('cpu'),
torch 2.2.2+cu121
tensor ops: 3.0
Traceback (most recent call last):
File "b1.py", line 7, in <module>
print(t.numpy())
^^^^^^^^^
RuntimeError: Numpy is not available
exit status: 1
2. What it means
- A compiled extension (here
torch._C) was built against NumPy 1.x, and NumPy 2 is installed. NumPy prints theA module that was compiled using NumPy 1.x cannot be run in NumPy 2.2.6banner plus a traceback-looking stack that is not an exception: it shows which import loaded the old module (import torch, line 3). - What happens next depends on the package. torch 2.2.2 carried on with a
UserWarning: Failed to initialize NumPy: _ARRAY_API not found; tensor maths still worked, and only.numpy()failed withRuntimeError: Numpy is not available. TensorFlow 2.15 instead fails the import outright (TensorFlow _ARRAY_API not found), and pandas built for 1.x does too (pandas _ARRAY_API not found). - pip may not warn you: this torch's metadata does not list numpy at all, so nothing stops numpy 2 being installed next to it.
3. Fix: pin numpy<2, or upgrade the module named in the stack
Option A, keep the old package and downgrade numpy:
$ pip install "numpy<2"
$ python b1.py
numpy 1.26.4
torch 2.2.2+cu121
tensor ops: 3.0
[1. 2.]
Option B, upgrade the package the stack points at to a release built for NumPy 2:
$ pip install -U torch # tested: 2.14.1+cpu
$ python b1.py
numpy 2.5.4
torch 2.14.1+cpu
tensor ops: 3.0
[1. 2.]
The banner's own hint is the same: downgrade to 'numpy<2' or try to upgrade the affected module. If several old packages are involved, pinning numpy<2 in requirements.txt is the quick fix; upgrading each one is the lasting one. Other NumPy 2 changes: NumPy 2 breaking changes, numpy.dtype size changed.
Frequently asked questions
What does "A module that was compiled using NumPy 1.x cannot be run in NumPy 2" mean?
A compiled extension was built against NumPy 1.x and NumPy 2 is installed. The stack printed under the banner shows which import loaded it.
How do I fix it?
pip install "numpy<2", or upgrade the package named in the stack to a version built for NumPy 2 (torch 2.14.1 worked with numpy 2.5.4 in this test).
Is the traceback after the message an error?
Not by itself: it is printed to show where the old module was imported. torch 2.2.2 kept running until .numpy() raised RuntimeError: Numpy is not available.
Written with AI assistance. Measured on 2026-10-24 on Linux: torch 2.2.2 on Python 3.11.17 with numpy 2.2.6 and 1.26.4, and torch 2.14.1+cpu with numpy 2.5.4 on Python 3.13.5. The script ran verbatim and the output was pasted unedited (venv path shortened). PlainTables is our extension; NumPy and PyTorch are free.