PyTorch is one of the most popular open-source machine learning frameworks used for building deep learning models and conducting AI research. It’s widely known for its flexibility, dynamic computation graph, and ease of use. If you’re running Windows 11 and want to start using PyTorch for your AI or data science projects, this guide will walk you through every step to get it installed properly.
Whether you’re a beginner working on neural networks or an advanced developer setting up GPU acceleration, this step-by-step guide covers both CPU and GPU installations.
What You’ll Need Before Installing PyTorch
Before you begin, make sure you meet the following requirements:
- A Windows 11 system with administrator privileges
- Python installed (version 3.8 or newer recommended)
- pip (Python’s package installer)
- An active internet connection
- (Optional) NVIDIA GPU with CUDA support if you plan to use GPU acceleration
If you don’t have Python or pip yet, it’s best to install the latest version from the official Python website.
Step 1: Verify Python and pip Installation
Before installing PyTorch, make sure Python and pip are properly installed and configured on your Windows 11 system.
- Open Command Prompt or Windows Terminal.
- Type the following commands to verify the installation:
python --version pip --version - If both commands show version numbers (for example, Python 3.11.5 and pip 24.0), you’re good to go.
If Python isn’t recognized, you may need to add it to the system PATH or reinstall Python and select the “Add Python to PATH” option during setup.
Step 2: Open the Official PyTorch Installation Page
Go to the official PyTorch Get Started page. This page automatically provides you with installation commands tailored to your system setup.
You’ll see a configuration selector with the following options:
- PyTorch Build: Stable (recommended) or Preview
- Your OS: Choose Windows
- Package: Select pip
- Language: Python
- Compute Platform: Choose either CPU or CUDA (for NVIDIA GPUs)
Once you make your selections, the site will generate the correct command for you.
Step 3: Install PyTorch Using pip
After configuring the installation command, copy it from the PyTorch site and run it in Command Prompt.
For CPU-only installation:
pip install torch torchvision torchaudio
For GPU (CUDA) installation:
If you have an NVIDIA GPU that supports CUDA, install the version with CUDA support. For example:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
Note: Replace cu121 with the version that matches your installed CUDA toolkit (e.g., cu118, cu122).
Wait for the installation process to complete. It may take several minutes depending on your internet speed.
Step 4: Verify the PyTorch Installation
Once installation is complete, verify that PyTorch is installed correctly by running the following Python commands:
- Open Python from Command Prompt:
python - Import PyTorch:
import torch print(torch.__version__) print("CUDA Available:", torch.cuda.is_available())
If the output shows the version number and “CUDA Available: True” (for GPU installations), your setup is complete.
Step 5: Test PyTorch with a Simple Program
You can test whether PyTorch can run simple operations by writing the following code in a Python file (for example, test_pytorch.py):
import torch
x = torch.rand(5, 5)
y = torch.rand(5, 5)
z = x + y
print("Tensor Addition Result:")
print(z)
if torch.cuda.is_available():
print("Running on GPU")
else:
print("Running on CPU")
Run the file using:
python test_pytorch.py
If everything is configured correctly, you should see the tensor output and whether the computation is using CPU or GPU.
Step 6: Updating PyTorch in the Future
You can easily update PyTorch when a new version is released using:
pip install --upgrade torch torchvision torchaudio
To check your current version:
python -m torch.utils.collect_env
This command displays all PyTorch environment details, including CUDA and library information.
Wrapping Up
Installing PyTorch on Windows 11 is straightforward when you follow the right steps. Whether you’re using a CPU or GPU setup, the official pip installation commands ensure you get the correct binaries for your environment.
Once installed, you can begin building and training machine learning models directly in Python using PyTorch. For best performance, always keep your Python, pip, and PyTorch versions up to date, and make sure your GPU drivers are properly maintained.
PyTorch opens the door to fast prototyping and efficient deep learning development — so now that it’s ready, you can start experimenting with neural networks, data processing, and AI projects right on your Windows 11 PC.