PyTorch is one of the most popular open-source libraries for machine learning and deep learning. Developers use it for tasks like image recognition, natural language processing, and AI model training. If you are setting up PyTorch for the first time, this guide walks you through the correct installation method based on your system and hardware.

Step 1: Check Your System Requirements
Before installing PyTorch, make sure your system meets these basic requirements:
- Python 3.8 or newer
- pip package manager
- Windows, macOS, or Linux operating system
If you plan to use GPU acceleration, your system must also have an NVIDIA GPU with updated drivers.
Step 2: Upgrade pip (Recommended)
An outdated pip version can cause installation errors. Update it before proceeding.
python -m pip install --upgrade pip
This step helps pip download the correct PyTorch wheel without dependency conflicts.
Step 3: Install PyTorch (CPU Version)
If you do not need GPU acceleration, install the CPU-only version. This option works on all systems and suits beginners.
pip install torch torchvision torchaudio
This command installs PyTorch along with commonly used vision and audio libraries.
Step 4: Install PyTorch with NVIDIA GPU Support (Optional)
If your system has an NVIDIA GPU, install PyTorch with CUDA support for better performance.
CUDA 12.1 (recommended for most users)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
CUDA 11.8 (for older GPUs)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Do not install a CUDA build if your system does not have an NVIDIA GPU. Use the CPU version instead.
Step 5: Verify the Installation
After installation, confirm that PyTorch works correctly.
python -c "import torch; print(torch.__version__)"
To check GPU support:
python -c "import torch; print(torch.cuda.is_available())"
If the command prints True, PyTorch detects your GPU correctly.
Common PyTorch Installation Errors and Fixes
- Using
pip install pytorchinstead oftorch - Installing a CUDA version without an NVIDIA GPU
- Skipping the pip upgrade step
- Mixing multiple Python versions on the same system
Avoiding these mistakes saves time and prevents setup issues.
Installing PyTorch is straightforward when you use the correct command for your system. The CPU version works well for learning and testing, while the CUDA version offers faster performance for deep learning workloads. Once installed, you can start building and training models immediately.
If new PyTorch versions are released, updating pip and reinstalling usually resolves compatibility issues.
