How to Fix "No Module Named torch"

Install PyTorch: pip install torch torchvision. For CUDA GPU support: pip install torch --index-url https://download.pytorch.org/whl/cu121

CPU Only (All Platforms)

pip install torch torchvision torchaudio

With CUDA GPU Support

# CUDA 12.1 (recommended for most modern GPUs)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

# CUDA 11.8 (older GPUs)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

With Conda

# CPU only
conda install pytorch torchvision torchaudio cpuonly -c pytorch

# CUDA 12.1
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

Common Issues

Wrong Python version

# Make sure pip matches your Python
python3 -m pip install torch
# or
python -m pip install torch

Virtual environment not activated

# Activate your venv first
source venv/bin/activate # Linux/Mac
venv\Scripts\activate   # Windows
pip install torch

Verify installation

python -c "import torch; print(torch.__version__)"
# Should print something like: 2.3.0

# Check CUDA availability
python -c "import torch; print(torch.cuda.is_available())"
Try HeyTensor Shape Calculator

TENSOR PREFLIGHT · DOWNLOADABLE PYTORCH TOOLKIT

Take the next step in your own PyTorch model.

Trace a local forward pass, inspect tensor shapes in an HTML report, and turn a repair into a regression check. Includes eight broken-and-fixed workflows, source code and setup instructions.

Python 3.9+ · PyTorch 2.8+ · Runs locally

Get Tensor Preflight — $29 One-time payment · ZIP download See a sample report
By the same builder: GitHub, theluckystrike BeLikeNative, Grammar AI EarlyThunder, Dev Blog Bug Bounty Reality Zovo, AI Dev Tools