Finding the Correct PyTorch Wheel URL from download.pytorch.org for uv: A Complete Guide

You can find the correct PyTorch wheel URL by matching your Python version tag (e.g., cp310-cp310) and CUDA version (e.g., cu124) with the index URLs at https://download.pytorch.org/whl/, then configuring uv to resolve these via optional dependencies in pyproject.toml.

Installing PyTorch with specific CUDA support using the uv package manager requires pinpointing the exact wheel URL from the official PyTorch repository. The baonguyen6742/uv-install-torch project demonstrates a reproducible workflow for finding the correct PyTorch wheel URL from download.pytorch.org for uv by leveraging optional dependency groups and index configuration in pyproject.toml.

How PyTorch Wheel URLs Are Structured on download.pytorch.org

Understanding the URL anatomy is essential for configuring uv correctly. PyTorch hosts wheels at https://download.pytorch.org/whl/ with subdirectories for each CUDA version (e.g., cpu, cu124, cu118).

The Wheel Filename Convention

Each wheel follows a strict naming pattern that encodes the package version, CUDA tag, Python interpreter tag, and platform:


torch-2.4.1+cu124-cp310-cp310-linux_x86_64.whl

Breaking this down:

  • Package: torch
  • Version: 2.4.1
  • CUDA tag: +cu124 (indicates CUDA 12.4 support)
  • Python tag: cp310-cp310 (CPython 3.10, both ABI and interpreter)
  • Platform: linux_x86_64

Index URLs for uv Configuration

According to the pyproject.toml in baonguyen6742/uv-install-torch, the relevant index URLs are:

  • CPU-only wheels: https://download.pytorch.org/whl/cpu
  • CUDA 12.4 wheels: https://download.pytorch.org/whl/cu124

These URLs serve as the base for uv's resolution algorithm when combined with optional dependencies.

Configuring uv to Resolve the Correct Wheel URL

The repository uses optional dependencies (extras) to switch between CPU and CUDA variants without hardcoding URLs in your installation commands.

The pyproject.toml Structure

In pyproject.toml, the project defines separate extras for each target platform:

[project.optional-dependencies]
cpu = ["torch==2.4.1", "torchvision==0.19.1", "torchaudio==2.4.1"]
cu124 = ["torch==2.4.1", "torchvision==0.19.1", "torchaudio==2.4.1"]

The critical configuration maps these extras to specific PyTorch indices:

[[tool.uv.sources]]
torch = [
    { index = "pytorch-cpu", extra = "cpu" },
    { index = "pytorch-cu124", extra = "cu124" }
]

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

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

Installing with the Correct Extra

To trigger resolution from the CUDA 12.4 index, run:

uv sync --extra cu124

This command instructs uv to:

  1. Activate the cu124 optional dependency group
  2. Resolve torch from the pytorch-cu124 index (https://download.pytorch.org/whl/cu124)
  3. Download the wheel matching your Python version tag (e.g., cp310-cp310) and platform

For CPU-only installations, substitute --extra cpu to target https://download.pytorch.org/whl/cpu.

Verifying the Wheel URL After Installation

Once installed, you can confirm that uv fetched the wheel from the correct PyTorch index.

Checking the Direct URL Metadata

According to PEP 610, uv records the download URL in direct_url.json within the package's metadata. Access this programmatically:

import importlib.metadata as md
import json

def get_wheel_url(package: str) -> str:
    """Retrieve the direct download URL for an installed package."""
    dist = md.distribution(package)
    try:
        direct_url = dist.read_text('direct_url.json')
        if direct_url:
            data = json.loads(direct_url)
            return data.get('url', 'URL not found')
        return "No direct URL recorded"
    except FileNotFoundError:
        return "Metadata not available"

# Verify PyTorch packages

print("torch:", get_wheel_url('torch'))
print("torchvision:", get_wheel_url('torchvision'))
print("torchaudio:", get_wheel_url('torchaudio'))

When run after uv sync --extra cu124, this outputs URLs beginning with https://download.pytorch.org/whl/cu124/, confirming the correct index was used.

Runtime Verification with main.py

The repository includes main.py to validate that the installed wheel supports CUDA:

import torch

print("torch version:", torch.__version__)
print("CUDA available:", torch.cuda.is_available())

if torch.cuda.is_available():
    for i in range(torch.cuda.device_count()):
        props = torch.cuda.get_device_properties(i)
        print(f"Device {i}: {props.name} (Compute Capability {props.major}.{props.minor})")

Execute with:

uv run main.py

Successful execution with a +cu124 version suffix and CUDA available: True proves that uv resolved and installed the wheel from https://download.pytorch.org/whl/cu124 matching your environment.

Summary

  • PyTorch wheel URLs follow a predictable structure at https://download.pytorch.org/whl/<cuda_version>/, where filenames encode Python version tags (e.g., cp310-cp310) and CUDA versions (e.g., +cu124).
  • Configure uv using optional dependencies (cpu or cu124) in pyproject.toml to map package names to specific PyTorch indices without manual URL handling.
  • Install the correct variant with uv sync --extra cu124, which resolves the wheel URL automatically based on your Python version and platform.
  • Verify the installation by inspecting direct_url.json metadata or running main.py to confirm CUDA support and the +cu124 version suffix.

Frequently Asked Questions

How do I determine which CUDA version tag to use in the PyTorch wheel URL?

Check your installed NVIDIA driver and CUDA toolkit version using nvidia-smi or nvcc --version. The repository supports cu124 (CUDA 12.4) and cpu variants. Match the CUDA tag in the URL (e.g., https://download.pytorch.org/whl/cu124) to your installed CUDA minor version for compatibility.

Can I use this method to install PyTorch on macOS or Windows?

Yes, the pyproject.toml configuration works across platforms, but the wheel URLs differ by platform suffix (e.g., macosx_11_0_arm64.whl for Apple Silicon, win_amd64.whl for Windows). The uv resolver automatically selects the correct platform-specific wheel from the download.pytorch.org index based on your operating system and architecture.

What does the +cu124 local version identifier mean in the PyTorch wheel filename?

The +cu124 suffix is a local version identifier defined in PEP 440. It indicates that this specific build of PyTorch 2.4.1 was compiled against CUDA 12.4 libraries. When you run torch.__version__ in Python, seeing 2.4.1+cu124 confirms that uv installed the CUDA-enabled wheel from https://download.pytorch.org/whl/cu124 rather than the CPU-only variant.

How can I verify that uv downloaded the wheel from the correct PyTorch index?

Inspect the package metadata using Python's importlib.metadata module to read the direct_url.json file, which uv populates according to PEP 610. This JSON file contains the exact download URL (e.g., https://download.pytorch.org/whl/cu124/torch-2.4.1%2Bcu124-cp310-cp310-linux_x86_64.whl). Alternatively, check torch.__version__ for the +cu124 suffix and run torch.cuda.is_available() to confirm CUDA support.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →