PyTorch RuntimeError: Numpy is not available (tested)

RuntimeError: Numpy is not available means torch cannot import numpy in the interpreter you are running: numpy is not installed there (torch does not depend on it). import torch already warns Failed to initialize NumPy: No module named 'numpy'. Install numpy with that same interpreter's python -m pip.

1. Reproduce

b1.py runs in a venv with torch but without numpy (torch does not require numpy, so pip install torch alone can leave you here):

import importlib.util
print("numpy installed:", importlib.util.find_spec("numpy") is not None)
import torch
print("torch", torch.__version__)
t = torch.arange(3)
print("tensor ops still work:", (t * 2).tolist())
for name, call in [("t.numpy()", lambda: t.numpy()), ("torch.from_numpy", lambda: torch.from_numpy([1, 2]))]:
    try:
        call()
    except Exception as e:
        print(f"{name} -> {type(e).__name__}: {e}")
numpy installed: False
/home/jacque/forever/scratch/tcpu/lib/python3.13/site-packages/torch/_subclasses/functional_tensor.py:368: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at /__w/pytorch/pytorch/torch/csrc/utils/tensor_numpy.cpp:84.)
  cpu = _conversion_method_template(device=torch.device("cpu"))
torch 2.14.1+cpu
tensor ops still work: [0, 2, 4]
t.numpy() -> RuntimeError: Numpy is not available
torch.from_numpy -> RuntimeError: Numpy is not available

Three things to notice: the UserWarning: Failed to initialize NumPy: No module named 'numpy' appears at import torch, which is the early hint; plain tensor maths keeps working; only the numpy bridge (.numpy(), torch.from_numpy) raises RuntimeError: Numpy is not available. Libraries that convert tensors to arrays (matplotlib plotting, scikit-learn, many dataloaders) hit the same error.

2. Fix: install numpy into the same interpreter

# Fix: install numpy into the SAME interpreter that runs torch
# (pip users: python -m pip install numpy)
uv pip install -q -p "$(which python)" numpy
python -c "import torch, numpy; t = torch.arange(3); print('numpy', numpy.__version__, '|', type(t.numpy()).__name__, t.numpy())"
numpy 2.5.4 | ndarray [0 1 2]

If numpy is installed and you still get the error, you are almost certainly running a different interpreter than the one you installed into (Jupyter kernel, IDE interpreter, another venv). Compare python -c "import sys; print(sys.executable)" with the path your notebook or IDE uses, and install with that exact python -m pip.

Related: Torch not compiled with CUDA enabled, pip install torch: no matching distribution found. If numpy is installed but you also see A module that was compiled using NumPy 1.x cannot be run in NumPy 2, see NumPy 1.x vs NumPy 2.

Frequently asked questions

What causes RuntimeError: Numpy is not available in PyTorch?

numpy cannot be imported in the interpreter running torch, usually because it is not installed there. torch.Tensor.numpy() and torch.from_numpy() then raise this error.

Does torch install numpy?

No. torch 2.14.1 does not require numpy, so pip install torch alone leaves .numpy() unusable until you install numpy.

I installed numpy but still get the error. Why?

You installed it into a different interpreter. Check sys.executable in the failing script or notebook and run that python -m pip install numpy.

Written with AI assistance. Measured on 2026-10-24 with torch 2.14.1+cpu, numpy 2.5.4 and Python 3.13.5 on Linux. The scripts ran verbatim and the output was pasted unedited. PlainTables is our extension; PyTorch and numpy are free.