How to Install torch in Python
Tensors and Dynamic neural networks in Python with strong GPU acceleration
pip install torch
What is torch?
Tensors and Dynamic neural networks in Python with strong GPU acceleration
PyTorch is a Python package that provides two high-level features: - Tensor computation (like NumPy) with strong GPU acceleration - Deep neural networks built on a tape-based autograd system
You can reuse your favorite Python packages such as NumPy, SciPy, and Cython to extend PyTorch when needed.
Our trunk health (Continuous Integration signals) can be found at hud.pytorch.org.
Quick Start
Minimal example to get started with torch:
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using: {device}")
x = torch.tensor([1.0, 2.0, 3.0]).to(device)
print(x.mean()) # tensor(2.)
Installation
pip (standard)
pip install torch
Virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install torch
pip3
pip3 install torch
conda
conda install -c conda-forge torch
Poetry
poetry add torch
Dependencies
Installing torch will also install these packages:
Verify the Installation
After installing, confirm the package is available:
python -c "import torch; print(torch.__version__)"
If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.
Installation Errors
Common errors when installing torch with pip.
ModuleNotFoundError: No module named 'torch'
Cause: The package is not installed in the current Python environment.
Fix: Run pip install torch. If using a virtual environment, ensure it is activated first.
ModuleNotFoundError: No module named 'torch' (installed but still failing)
Cause: pip installed the package into a different Python than the one running your script.
Fix: Use python -m pip install torch to install into the interpreter you are running.
ImportError: cannot import name 'X' from 'torch'
Cause: The function or class does not exist in the installed version.
Fix: Check the version with pip show torch and upgrade with pip install --upgrade torch.
pip: command not found
Cause: pip is not in PATH or Python was not added to PATH during installation.
Fix: Try python -m pip install torch. On macOS/Linux try pip3.
PermissionError: [Errno 13] Permission denied
Cause: No write access to the system Python package directory.
Fix: Use a virtual environment, or add --user: pip install --user torch
SSL: CERTIFICATE_VERIFY_FAILED
Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.
Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org torch
RuntimeError: CUDA out of memory
Cause: Model or batch size exceeds GPU memory.
Fix: Reduce batch size, call torch.cuda.empty_cache(), or run on CPU.
Recent Releases
| Version | Released |
|---|---|
2.11.0 latest |
2026-03-23 |
2.10.0 |
2026-01-21 |
2.9.1 |
2025-11-12 |
2.9.0 |
2025-10-15 |
2.8.0 |
2025-08-06 |
Manage torch
Upgrade to latest version
pip install --upgrade torch
Install a specific version
pip install torch==2.11.0
Uninstall
pip uninstall torch
Check what is installed
pip show torch