Getting same error for numpy 2.0 as of March 18th 2025.

Current solution is to install the latest version of numpy 1 (1.26.4) instead:

Copypip install "numpy<2"

You will likely have to restart the kernel afterwards.

Answer from Talha Tayyab on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › torch is being built with the wrong version of numpy (with pip)
r/learnpython on Reddit: Torch is being built with the wrong version of NumPy (with pip)
April 13, 2025 -

Hello, I need help with the problem I'm trying to solve for a few days now. I have to run a project which uses a bunch of packages, including NumPy 1.22 and PyTorch 1.13. I'm using Windows 10 and Python 3.10.11 with pip 23.0.1. When I install the appropriate versions of the packages and try to run the project, I'm getting error: Failed to initialize NumPy: module compiled against API version 0x10 but this version of numpy is 0xf (Triggered internally at ..\torch\csrc\utils\tensor_numpy.cpp:77.). AFAIK 0xf is 1.22 (the version I have installed) and 0x10 is 1.23/1.24.

What I tried:

  1. Reinstalling Python including removing everything Python-related (like files in %APPDATA%) to be sure that no versions of NumPy and PyTorch exist in my system (except for packages bundled in some software that I don't want to uninstall).

  2. Checking the Path variable to be sure that the correct version of Python and pip is used.

  3. Using venv to have a clear environment.

But still somehow torch seems to be installed with NumPy 1.23/1.24 despite the fact that I have no such version of that package in my system (I searched my entire disk). When I import NumPy and print the version and the path, it correctly shows version 1.22 and the path to the package in venv I created.

I also can't update to the newest version of NumPy (or to 1.23/1.24) because then I get incompatibility with SciPy version. I also can't upgrade the project's requirements, the code is from a paper I'm not the author of so it would be cumbersome.

Discussions

NumPy 2.1.0 Compatibility Issue with PyTorch 2.4.0: Importing PyTorch with NumPy 2.1.0 Causes _ARRAY_API not found Error
Attempting to import PyTorch (torch) in a Python script results in a compatibility error related to NumPy. The error indicates that a module compiled using NumPy 1.x cannot be run with NumPy 2.1.0 due to potential crashes. It suggests that modules must be compiled with NumPy 2.0 or newer to support both versions... More on github.com
🌐 github.com
4
September 3, 2024
python - Why does torch import complain about numpy version - Stack Overflow
I created a virtual environment on MacOS and installed pytorch with pip: python -m env torch-env source torch-env/bin/activate pip install torch torchvision torchaudio Launching python and importing More on stackoverflow.com
🌐 stackoverflow.com
Version compatibility guide
ok, i was just ignorant of the fact that numpy 2 was released like 2 days ago. it seems to work with any reasonable version that starts with 1 More on reddit.com
🌐 r/pytorch
4
5
June 18, 2024
Numpy Version?
Does pytorch3d only support numpy and numpy-base with version >= 1.21? More on github.com
🌐 github.com
6
March 9, 2022
🌐
GitHub
github.com › pytorch › pytorch › issues › 107302
NumPy 2.0 Support · Issue #107302 · pytorch/pytorch
August 16, 2023 - Once we have a NumPy 2.0 compatible available, upgrade all our binary build to this version of NumPy and remove the error message above. This will ensure that our produced binaries work with any version of NumPy (including <2.0) Make torch.compile ...
Author   pytorch

Getting same error for numpy 2.0 as of March 18th 2025.

Current solution is to install the latest version of numpy 1 (1.26.4) instead:

Copypip install "numpy<2"

You will likely have to restart the kernel afterwards.

Answer from Talha Tayyab on Stack Overflow
🌐
GitHub
github.com › pytorch › pytorch › issues › 135013
NumPy 2.1.0 Compatibility Issue with PyTorch 2.4.0: Importing PyTorch with NumPy 2.1.0 Causes _ARRAY_API not found Error · Issue #135013 · pytorch/pytorch
September 3, 2024 - 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' ...
Author   pytorch
🌐
PyTorch Foundation
pytorch.org
PyTorch Foundation
Note that LibTorch is only available for C++. NOTE: Latest Stable PyTorch requires Python 3.10 or later. ... pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 Previous versions of PyTorch
🌐
GitHub
github.com › deepinv › deepinv › discussions › 349
torch + numpy versions on Windows · deepinv/deepinv · Discussion #349
Now that we have unpinned the numpy version in #329, if you want to upgrade to numpy 2, you must also upgrade your pytorch to >2.4.1. Otherwise you may get the error: A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.1 as ...
Author   deepinv
🌐
Stack Overflow
stackoverflow.com › questions › 79532275 › why-does-torch-import-complain-about-numpy-version
python - Why does torch import complain about numpy version - Stack Overflow
most likely the pytorch wheel you installed was compiled with numpy 1.x. There are a few github issues on this error - the solution seems to be upgrading the pytorch version ... numpy 2.0 simply didn't exist when torch 2.2.2 was released, and ...
Find elsewhere
🌐
Reddit
reddit.com › r/pytorch › version compatibility guide
r/pytorch on Reddit: Version compatibility guide
June 18, 2024 -

Is there somewhere a searchable version compatibility database? As in all python projects reconciling versions is a pretty annoying problem, I meet it again and again.

Currently I try to use pytorch2.3.1 with cuda 11.8 , python 3.11.2 . It seems like I cannot get rid of a warning ( UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at ..\torch\csrc\utils\tensor_numpy.cpp:84 ).

Id guess its caused by an incorrect numpy version. Is there a place to look up what combination of torch-cuda-python-numpy is ok and which is not?

🌐
NumPy
numpy.org › doc › stable › user › basics.interoperability.html
Interoperability with NumPy — NumPy v2.4 Manual
PyTorch does not implement __array_function__ or __array_ufunc__. Under the hood, the Tensor.__array__() method returns a NumPy ndarray as a view of the tensor data buffer. See this issue and the __torch_function__ implementation for details.
🌐
NumPy
numpy.org › doc › 2.2 › user › basics.interoperability.html
Interoperability with NumPy — NumPy v2.2 Manual
PyTorch does not implement __array_function__ or __array_ufunc__. Under the hood, the Tensor.__array__() method returns a NumPy ndarray as a view of the tensor data buffer. See this issue and the __torch_function__ implementation for details.
🌐
PyPI
pypi.org › project › torch
torch · PyPI
You can write new neural network layers in Python using the torch API or your favorite NumPy-based libraries such as SciPy.
      » pip install torch
    
Published   May 13, 2026
Version   2.12.0
🌐
GitHub
github.com › pytorch › pytorch › issues › 147122
PyTorch build with numpy version incompatibility · Issue #147122 · pytorch/pytorch
February 13, 2025 - I'm building the latest PyTorch ... may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0....
Author   pytorch
🌐
NumPy
numpy.org › doc › 2.1 › user › basics.interoperability.html
Interoperability with NumPy — NumPy v2.1 Manual
PyTorch does not implement __array_function__ or __array_ufunc__. Under the hood, the Tensor.__array__() method returns a NumPy ndarray as a view of the tensor data buffer. See this issue and the __torch_function__ implementation for details.
🌐
GitHub
github.com › qiskit-community › qiskit-machine-learning › issues › 812
Pinned `torch==2.2.2` breaks CI due to `numpy>=2.0` · Issue #812 · qiskit-community/qiskit-machine-learning
July 2, 2024 - https://github.com/qiskit-community/qiskit-machine-learning/actions/runs/9753721897/job/26919448830#step:8:2473 because version 2.2.2 of PyTorch, pinned in #796, is no longer compatible with Numpy following the v. 2.0 release.
Author   qiskit-community
🌐
PyTorch Forums
discuss.pytorch.org › t › getting-runtimeerror-numpy-is-not-available-whenever-trying-with-torch-from-numpy › 206871
Getting "RuntimeError: Numpy is not available" whenever trying with "torch.from_numpy" - PyTorch Forums
July 24, 2024 - When I try to run a simple code, I receive an error saying that Numpy is not available. import torch import numpy as np data = np.array([1, 2, 3], dtype=np.uint8) tensor = torch.from_numpy(data) Traceback (most recent call last): File ...