Skip to main content

How to Install PyTorch with CUDA Using uv

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

On Windows, uv add torch gives a PyTorch that can't use an NVIDIA GPU, because PyPI's Windows build has no CUDA. PyTorch publishes its CUDA builds on its own package index, and uv can take them from there for Windows only. This guide sets that up for CUDA 13.2 with PyTorch 2.15.0, and checks what each operating system gets.

Syntax​

Syntax (pyproject.toml)
[tool.uv.sources]
<package> = [
{ index = "<index name>", marker = "<which systems>" },
]

[[tool.uv.index]]
name = "<index name>"
url = "https://download.pytorch.org/whl/<CUDA version>"
explicit = true
PartWhat it means
[tool.uv.sources]Where uv gets particular packages from, instead of PyPI
<package>A package to take from the index: torch, and torchvision with it
index = "<index name>"The index to use, by the name it's given below
marker = "<which systems>"Uses the index only on the systems the marker matches. sys_platform == 'win32' means Windows
[[tool.uv.index]]Declares an extra package index
urlPyTorch's index for one CUDA version: cu132 is CUDA 13.2
explicit = trueUses the index only for the packages that name it

The uv guide to PyTorch explains the last one: "We recommend the use of explicit = true to ensure that the index is only used for torch, torchvision, and other PyTorch-related packages, as opposed to generic dependencies like jinja2, which should continue to be sourced from the default index (PyPI)."

The Example​

A project named cuda-demo needs PyTorch and torchvision, with CUDA on Windows. Why only Windows? PyTorch's install selector gives, for CUDA 13.2:

  • Windows: pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu132, PyTorch's own index.
  • Linux: pip3 install torch torchvision, plain PyPI, because PyPI's Linux build already uses CUDA 13.2.
  • macOS: plain PyPI. Macs have no CUDA; PyTorch uses their GPU through MPS.

So the CUDA index goes to Windows alone. I built this on a Mac: every output below is real, and the last step, running it on Windows, is the one I couldn't perform.

Prerequisites​

  • uv. This guide uses uv 0.13.10 with Python 3.15.2.
  • On the Windows PC that will run it: an NVIDIA GPU with its driver installed.

Step 1: Create the Project​

Terminal
uv init --python 3.15 cuda-demo
cd cuda-demo
Output
Initialized project `cuda-demo` at `/Users/you/source/cuda-demo`

The terminal after uv init --python 3.15 cuda-demo: Initialized project cuda-demo.

Step 2: Point PyTorch at the CUDA Index on Windows​

Open pyproject.toml and add these lines at the end:

pyproject.toml (the end)
[tool.uv.sources]
torch = [
{ index = "pytorch-cu132", marker = "sys_platform == 'win32'" },
]
torchvision = [
{ index = "pytorch-cu132", marker = "sys_platform == 'win32'" },
]

[[tool.uv.index]]
name = "pytorch-cu132"
url = "https://download.pytorch.org/whl/cu132"
explicit = true

The lines added to pyproject.toml in a macOS-style code window: tool.uv.sources sends torch and torchvision to the pytorch-cu132 index when sys_platform is win32, and tool.uv.index declares that index at download.pytorch.org/whl/cu132 with explicit set to true.

torch and torchvision both name the index, because the two must come from the same build. The name pytorch-cu132 is only a label: any name works, as long as both places use the same one.

Step 3: Add PyTorch​

Terminal
uv add torch torchvision
Output
Using CPython 3.15.2 interpreter at: /Library/Frameworks/Python.framework/Versions/3.15/bin/python3.15
Creating virtual environment at: .venv
Resolved 33 packages in 2.47s
Built cuda-demo @ file:///Users/you/source/cuda-demo
Prepared 3 packages in 981ms
Installed 14 packages in 323ms
+ cuda-demo==0.1.0 (from file:///Users/you/source/cuda-demo)
+ filelock==4.3.2
+ fsspec==2026.9.0
+ jinja2==3.1.6
+ markupsafe==3.0.4
+ mpmath==1.3.0
+ networkx==3.7
+ numpy==2.5.5
+ pillow==13.0.0
+ setuptools==84.2.1
+ sympy==1.14.0
+ torch==2.15.0
+ torchvision==0.29.2
+ typing-extensions==4.16.0

The terminal after uv add torch torchvision: 33 packages resolved and 14 installed on the Mac, among them torch 2.15.0 and torchvision 0.29.2.

uv resolved one lockfile for every system and installed the Mac's builds here, since the marker leaves the CUDA index out on macOS. The complete file now:

pyproject.toml
[project]
name = "cuda-demo"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
authors = [
{ name = "Your Name", email = "you@example.com" }
]
requires-python = ">=3.15"
dependencies = [
"torch>=2.15.0",
"torchvision>=0.29.2",
]

[project.scripts]
cuda-demo = "cuda_demo:main"

[build-system]
requires = ["uv_build>=0.13.10,<0.14.0"]
build-backend = "uv_build"

[tool.uv.sources]
torch = [
{ index = "pytorch-cu132", marker = "sys_platform == 'win32'" },
]
torchvision = [
{ index = "pytorch-cu132", marker = "sys_platform == 'win32'" },
]

[[tool.uv.index]]
name = "pytorch-cu132"
url = "https://download.pytorch.org/whl/cu132"
explicit = true

The authors line holds the name and email from your Git settings.

Step 4: Check What Each System Gets​

uv tree shows the project's packages from the lockfile, and --python-platform picks the system to show them for. --depth 1 lists only the project's direct dependencies.

Terminal
uv tree --python-platform windows --depth 1
Output
Resolved 33 packages in 4ms
cuda-demo v0.1.0
├── torch v2.15.0+cu132
└── torchvision v0.29.2+cu132
Terminal
uv tree --python-platform macos --depth 1
Output
Resolved 33 packages in 5ms
cuda-demo v0.1.0
├── torch v2.15.0
└── torchvision v0.29.2
Terminal
uv tree --python-platform linux --depth 1
Output
Resolved 33 packages in 6ms
cuda-demo v0.1.0
├── torch v2.15.0
└── torchvision v0.29.2

The terminal after the three uv tree commands: Windows gets torch v2.15.0+cu132 and torchvision v0.29.2+cu132, while macOS and Linux get torch v2.15.0 and torchvision v0.29.2.

Windows gets torch v2.15.0+cu132: the +cu132 part marks PyTorch's CUDA 13.2 build. macOS and Linux get PyPI's torch v2.15.0. The commands work unchanged in PowerShell.

The CUDA build is big: the Windows file for torch 2.15.0+cu132 is 2.12 GB, against 126.7 MB for PyPI's Windows build without CUDA.

Step 5: Run It on Windows​

On the Windows PC, in the project folder, install what the lockfile lists and ask PyTorch whether it can reach the GPU:

PowerShell
uv sync
uv run python -c "import torch; print(torch.__version__); print(torch.cuda.is_available())"

uv sync installs exactly what uv.lock lists for this system. PyTorch's install page describes the second line's check as the way "to check if your GPU driver and CUDA is enabled and accessible by PyTorch". I couldn't run this step: this guide was written on a Mac, which has no CUDA.

Common Mistakes​

MistakeWhat happensDo this instead
Leaving out the markerOn a Mac, uv add torch failed: Distribution `torch==2.15.0+cu132 @ registry+https://download.pytorch.org/whl/cu132` can't be installed because it doesn't have a source distribution or wheel for the current platformAdd marker = "sys_platform == 'win32'", as Fixed: Distribution torch==2.15.0+cu132 can't be installed shows
Pointing only torch at the indextorchvision comes from PyPI, a different buildList both, as Step 2 does
Leaving out explicit = trueuv may look for other packages on PyTorch's index tooKeep explicit = true

FAQ​

Which CUDA version should I pick?​

PyTorch's selector offers CUDA 13.2 and 13.4 for PyTorch 2.15.0. CUDA 13.2 is the one PyPI's Linux build uses; for 13.4, use cu134 in the URL.

Does a Mac ever get the CUDA build?​

No. PyTorch's CUDA index has no macOS builds: its torch 2.15.0+cu132 files are for Linux and Windows only. A Mac uses its GPU through MPS, which PyPI's build already has.

Conclusion​

Two [tool.uv.sources] entries with marker = "sys_platform == 'win32'" and one explicit [[tool.uv.index]] for cu132 made the lockfile list torch v2.15.0+cu132 and torchvision v0.29.2+cu132 for Windows, while macOS and Linux kept PyPI's torch v2.15.0.

Additional Resources​