Fixed: UserWarning: Failed to initialize NumPy: No module named 'numpy'
A brand-new PyTorch project printed UserWarning: Failed to initialize NumPy: No module named 'numpy' as soon as it imported torch, and turning a tensor into a NumPy array then failed with RuntimeError: Numpy is not available. PyTorch doesn't install NumPy for you. Adding NumPy to the project fixed both.
What I Was Doing
I made a small project with uv on Python 3.15.2 and added PyTorch 2.15.0, and nothing else:
uv init --python 3.15 tensor-demo
cd tensor-demo
uv add torch
The script makes a tensor of three ones, prints it, then prints it as a NumPy array:
import torch
numbers = torch.ones(3)
print(numbers)
print(numbers.numpy())
uv run python to_numpy.py
What I Expected
The tensor, then the same three ones as a NumPy array:
tensor([1., 1., 1.])
[1. 1. 1.]
What I Got
A warning first, then the tensor, then an error:
/Users/you/source/tensor-demo/.venv/lib/python3.15/site-packages/torch/_subclasses/functional_tensor.py:377: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at /Users/runner/work/pytorch/pytorch/torch/csrc/utils/tensor_numpy.cpp:82.)
cpu = _conversion_method_template(device=torch.device("cpu"))
tensor([1., 1., 1.])
Traceback (most recent call last):
File "/Users/you/source/tensor-demo/to_numpy.py", line 5, in <module>
print(numbers.numpy())
~~~~~~~~~~~~~^^
RuntimeError: Numpy is not available
![The terminal after uv run python to_numpy.py: a UserWarning that NumPy failed to initialize because there's no module named numpy, then tensor([1., 1., 1.]), then a traceback ending in RuntimeError: Numpy is not available.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/ai/pytorch/fixes/2026/pytorch-numpy-01-warning.webp)
The warning came from inside PyTorch while it was being imported, before my first line ran. Plain tensor work still went on, so a script that never touches NumPy shows only the warning. numbers.numpy() is where it really broke.
What I Checked
I asked uv which packages PyTorch itself requires:
uv pip show torch
Name: torch
Version: 2.15.0
Location: /Users/you/source/tensor-demo/.venv/lib/python3.15/site-packages
Requires: filelock, fsspec, jinja2, networkx, setuptools, sympy, typing-extensions
Required-by: tensor-demo

NumPy isn't on the list, so uv add torch never installed it. The uv add output agreed: it installed 11 packages, and none of them was NumPy.
Why It Happens
PyTorch can work with NumPy arrays, but it doesn't depend on NumPy, so installing PyTorch doesn't bring it in. When torch is imported, it tries to load NumPy for those conversions and prints the warning if it can't. Anything that needs NumPy, such as tensor.numpy(), then fails with RuntimeError: Numpy is not available.
PyTorch's installation page puts NumPy among the things to have ready: "Please ensure that you have met the prerequisites below (e.g., numpy), depending on your package manager."
You won't see this in projects that already have NumPy through another package, such as Hugging Face Transformers, which depends on it. It shows up in a project that has PyTorch alone.
The warning has been discussed on PyTorch's tracker for years: issue #60252 reports this exact message, and issue #125678 asks for it to go away when NumPy isn't needed. Both are open.
The Fix
Add NumPy to the project:
uv add numpy
Resolved 29 packages in 207ms
Built tensor-demo @ file:///Users/you/source/tensor-demo
Prepared 1 package in 3ms
Uninstalled 1 package in 0.82ms
Installed 2 packages in 25ms
+ numpy==2.5.5
~ tensor-demo==0.1.0 (from file:///Users/you/source/tensor-demo)

uv add also records NumPy in pyproject.toml and uv.lock, so anyone who installs the project gets it too.
After the Fix
uv run python to_numpy.py
tensor([1., 1., 1.])
[1. 1. 1.]
![The terminal after the fix: tensor([1., 1., 1.]), then [1. 1. 1.], with no warning and no error.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/ai/pytorch/fixes/2026/pytorch-numpy-04-fixed.webp)
No warning, and the tensor turned into a NumPy array. The commands work unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Installing NumPy globally with pip install numpy outside the project | The project's own environment still doesn't have it, so the warning stays | Add it to the project: uv add numpy |
Hiding the warning with Python's warnings filters | With -W ignore::UserWarning the message went away, but tensor.numpy() still failed with RuntimeError: Numpy is not available | Install NumPy |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
UserWarning: Failed to initialize NumPy: No module named 'numpy' on import torch | NumPy isn't in the project | uv add numpy |
RuntimeError: Numpy is not available from tensor.numpy() | The same | uv add numpy |
FAQ
Is the warning harmful if I never use NumPy?
No. Tensor work runs without it. But many libraries that sit on top of PyTorch convert to NumPy somewhere, so adding it saves surprises later.
Which NumPy version should I install?
Let uv choose: uv add numpy picked 2.5.5, the newest, which works with PyTorch 2.15.0.
Conclusion
UserWarning: Failed to initialize NumPy: No module named 'numpy' meant exactly what it said: PyTorch 2.15.0 doesn't install NumPy. uv add numpy put it in the project, and both the warning and RuntimeError: Numpy is not available went away.
Additional Resources
- Start Locally — PyTorch's installation page and its prerequisites.
- torch.Tensor.numpy — the conversion that needs NumPy.
- pytorch/pytorch issue #125678 — the open request to drop the warning when NumPy isn't needed.
