How to Install PyTorch (2026): Windows, Mac, Linux & CUDA
PyTorch 2.12.0 installs in under two minutes on most machines. The right command depends on three choices: your OS, whether you have an NVIDIA GPU or Apple Silicon, and whether you prefer pip or conda. This guide gives you the exact command for your setup , plus verification steps and fixes for the five most common installation errors.
Prerequisites , Before You Install
Before running any install command, confirm your environment meets these requirements. Skipping this step is the single most common reason installation appears to succeed but import torch fails or the wrong Python picks up the package.
pip vs conda: which should you use?
Use pip if you're working in a standard Python virtual environment, a Docker container, or a CI/CD pipeline. It's faster and produces smaller installs. Use conda if you're on Windows with a CUDA GPU , conda bundles the CUDA runtime libraries, so you don't need to install the CUDA toolkit separately. This is a significant time savings for new GPU setups.
Quick Install: CPU-Only (All Platforms)
If you don't have a GPU, or you just want to get started immediately, the CPU-only pip install works on Windows, macOS, and Linux with a single command.
pip install torch torchvision torchaudio
This installs the three core packages: torch (the core framework), torchvision (image datasets and model zoo), and torchaudio (audio processing). All three are versioned together ; don't install them independently or you risk version mismatches.
The CPU-only package is roughly 250 MB. It runs on any hardware including laptops without dedicated GPUs. For learning, prototyping, and inference workloads on small models, CPU-only is sufficient. For training large neural networks, you'll want GPU acceleration , see the CUDA and Apple MPS sections below.
python -c "import torch; x = torch.rand(5, 3); print(x)"
If you see a 5×3 matrix of random numbers, PyTorch is working correctly.
CUDA GPU Installation (Windows & Linux)
GPU-accelerated PyTorch requires matching your CUDA version to the right wheel. PyTorch 2.12.0 supports CUDA 12.6, CUDA 13.0, and CUDA 13.2. The conda approach is recommended for Windows because it bundles the CUDA libraries automatically.
Option 1: conda (recommended for Windows, easy CUDA setup)
conda install pytorch torchvision torchaudio pytorch-cuda=12.6 -c pytorch -c nvidia
The pytorch-cuda=12.6 flag tells conda to install the CUDA 12.6 runtime alongside PyTorch. You still need your NVIDIA GPU driver installed (run nvidia-smi to verify), but you don't need a separate CUDA toolkit installation. This is the fastest path from zero to GPU-accelerated PyTorch on Windows.
Option 2: pip with CUDA wheels
For pip-based CUDA installs, the exact command depends on your CUDA version. Use the official selector at pytorch.org/get-started/locally to generate the correct command. For CUDA 12.6, the general form is:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
python -c "import torch; print(torch.cuda.is_available())" # Expected output: True python -c "import torch; print(torch.cuda.get_device_name(0))" # Expected output: your GPU name, e.g. NVIDIA GeForce RTX 4090
If torch.cuda.is_available() returns False after a CUDA install, the most common causes are: NVIDIA driver not installed, CUDA version mismatch between the wheel and your driver, or a virtual environment that picked up a different PyTorch installation. See the Troubleshoot section at the end of this guide.
ROCm for AMD GPUs (Linux only)
PyTorch 2.12.0 supports AMD GPU acceleration via ROCm 7.2 on Linux. Generate the exact ROCm install command from pytorch.org/get-started/locally after selecting your AMD ROCm version. ROCm support is Linux-only ; Windows AMD GPU users should use the CPU build.
macOS Installation (Apple Silicon & Intel)
macOS installation uses pip3 regardless of whether you're on Apple Silicon or Intel. The difference is what GPU acceleration you get afterward.
Apple Silicon (M1/M2/M3/M4) , MPS acceleration
pip3 install torch torchvision torchaudio
On Apple Silicon Macs, this installs a native ARM64 build of PyTorch with Metal Performance Shaders (MPS) support included. MPS lets PyTorch use the unified memory GPU in your M-series chip , no CUDA, no extra configuration. After installing, verify MPS:
python -c "import torch; print(torch.backends.mps.is_available())" # Expected output: True (on Apple Silicon)
To use MPS in your code, move tensors and models to the MPS device:
device = torch.device("mps" if torch.backends.mps.is_available() else "cpu")
model = MyModel().to(device)
x = x.to(device)
Intel Mac , CPU only
Intel Macs use the same pip3 install torch torchvision torchaudio command. PyTorch does not support CUDA on macOS (NVIDIA stopped CUDA support for macOS in CUDA 10.2). Intel Mac users get CPU-only acceleration. For GPU-accelerated training on macOS hardware, you need an Apple Silicon Mac.
macOS minimum requirement: macOS 10.15 Catalina or higher. Python 3.10–3.14 is required , the system Python on older macOS versions is typically 3.9 or earlier and is not supported.
Linux Installation
Linux is the most fully supported PyTorch platform. All CUDA versions, ROCm, and CPU builds are available. The minimum system requirement is glibc 2.28 or higher, which corresponds to Ubuntu 20.04+, Debian 10+, CentOS 8+, Fedora 24+, and Linux Mint 20+.
CPU-only (any distro)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
CUDA on Linux (pip)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
CUDA on Linux (conda)
conda install pytorch torchvision torchaudio pytorch-cuda=12.6 -c pytorch -c nvidia
NVIDIA Jetson (edge devices)
For NVIDIA Jetson platforms (Nano, TX1/TX2, Xavier NX/AGX, AGX Orin), PyTorch requires JetPack 4.2 or higher. Install using the NVIDIA-provided wheel for your JetPack version rather than standard pip , the standard wheel will not have the correct ARM library linkages.
Verify Your Installation
Run through these five verification steps in order. Each step builds on the previous , if step 2 fails, there's no point running step 4. Check each one off as you go.
-
Basic import test python -c "import torch; print(torch.__version__)" → should print 2.12.0
-
Tensor creation test python -c "import torch; x = torch.rand(5, 3); print(x)" → prints a 5×3 matrix
-
CUDA availability (GPU users) python -c "import torch; print(torch.cuda.is_available())" → True
-
Apple MPS check (Apple Silicon) python -c "import torch; print(torch.backends.mps.is_available())" → True
-
torchvision import python -c "import torchvision; print(torchvision.__version__)" → should match torch version
Building from Source (Advanced)
Building from source gives you a PyTorch build customized for your exact hardware and lets you test unreleased features from the main branch. It is significantly more complex than pip or conda and is not recommended for most users.
For source build instructions, refer to the official PyTorch GitHub README. The process involves cloning the repository, installing build dependencies (cmake, ninja, pybind11, etc.), setting environment variables for CUDA paths, and running the build script.
Common Installation Errors Fixed
These are the five errors that account for the majority of PyTorch installation failures. Each has a deterministic fix.
PyTorch installed into a different Python environment than the one you're running. Verify which Python is active:
which python # or: where python (Windows)
python -m pip show torch
If pip show torch shows nothing, you installed into a different environment. Activate the correct virtual environment or use python -m pip install torch (not just pip install) to ensure pip targets your current Python interpreter.
Three common causes:
1. CPU-only wheel installed: Run python -c "import torch; print(torch.version.cuda)". If it prints None, you have the CPU build. Uninstall and reinstall with the CUDA wheel.
2. CUDA version mismatch: Your PyTorch CUDA wheel (e.g., cu126) requires a driver that supports that CUDA version. Run nvidia-smi and check the CUDA version shown in the top-right. Your driver's CUDA version must be >= the wheel's CUDA version.
nvidia-smi
# Look for: CUDA Version: 12.6 (or higher)
3. No NVIDIA GPU present: Confirmed by nvidia-smi failing with "command not found". Use the CPU build or switch to Apple MPS (Mac only).
The conda solver can't resolve dependencies, often because the base environment has conflicting package versions. Two fixes:
# Fix 1: Create a fresh environment
conda create -n pytorch-env python=3.12
conda activate pytorch-env
conda install pytorch torchvision torchaudio pytorch-cuda=12.6 -c pytorch -c nvidia
# Fix 2: Use libmamba solver (faster, better conflict resolution)
conda install -n base conda-libmamba-solver
conda config --set solver libmamba
Windows DLL errors on import torch usually mean the Visual C++ redistributables are missing. Install the latest Microsoft Visual C++ Redistributable (x64). If using a CUDA build, also ensure your NVIDIA driver is up to date. A second common cause is antivirus software blocking PyTorch DLL loading , add your Python virtual environment directory to your antivirus exclusion list.
You installed the x86_64 (Intel) PyTorch wheel via Rosetta 2 on an Apple Silicon Mac. Verify your Python architecture:
python -c "import platform; print(platform.machine())"
# Should print: arm64 (not x86_64)
If it prints x86_64, you're running an Intel Python binary through Rosetta. Install a native ARM64 Python from python.org (look for the "macOS 64-bit universal2 installer") and reinstall PyTorch in a fresh environment with that Python.