uv: Installing PyTorch: An index URL could not be queried

Setup is:

uv init
uv venv --python 3.10

Leading to the simple pyproject.toml:

[project]
name = "test2"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"

Trying to install torch with:

uv add torch torchvision torchaudio --default-index https://download.pytorch.org/whl/cu118

leads to the error:

error: Distribution `torchaudio==2.0.0 @ registry+https://download.pytorch.org/whl/cu118` can't be installed because it doesn't have a source distribution or wheel for the current platform

Alternatively using pip:

uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

leads to a different error:

⠋ lit==15.0.7                                                                                                                                                                     × Failed to download and build `lit==15.0.7`
  ├─▶ Failed to resolve requirements from `build-system.requires`
  ├─▶ No solution found when resolving: `setuptools>=40.8.0`, `wheel`
  ╰─▶ Because wheel was not found in the package registry and you require wheel, we can conclude that your requirements are unsatisfiable.

      hint: An index URL (https://download.pytorch.org/whl/cu118) could not be queried due to a lack of valid authentication credentials (403 Forbidden).

I am on a Linux System and use uv 0.4.24.

Using virtualenv and normal pip works fine, thus I suspect a problem with uv here.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (12 by maintainers)

Most upvoted comments

@Leon0402 There is a PR (https://github.com/astral-sh/uv/pull/6523) document about installing PyTorch for UV. Perhaps you could also participate in the discussion and share your insights. Considering the complexities of PyTorch, additional perspectives would be beneficial for refining the documentation.

@FishAlchemist It seems to generally work quite well when manually editing the toml file. Here is a version that works for me for instance:

[project]
name = "name"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
    "torch==2.4.0+cu118",
    "torchvision==0.19.0+cu118",
]

[tool.uv.sources]
torch = { index = "pytorch" }
torchvision = { index = "pytorch" }

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

Related to https://github.com/astral-sh/uv/issues/8341 I think. Probably the CLI tools need a little bit more work and then UV could have some special documentation for torch. I know that torch always is a great source of confusion, because getting it right with cuda is not easy (and probably also not possible right now in the most generic way). I have not yet tested how well this approach works in transitive setups though (where a dependency specifies torch, but we need to overwrite it with a specific cuda version) or in a more generic way (where different people need different cuda versions).