uv icon indicating copy to clipboard operation
uv copied to clipboard

Installing PyTorch: An index URL could not be queried

Open Leon0402 opened this issue 1 year ago • 8 comments

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.

Leon0402 avatar Oct 18 '24 18:10 Leon0402

You probably need torchaudio==2.0.0+cu118 and the same for torchvision and torch.

charliermarsh avatar Oct 18 '24 18:10 charliermarsh

The hint at the end looks like a red herring. I guess the PyTorch index is (for some reason) returning a 403 for packages that aren't found, which seems wrong to me, but that's a PyTorch bug:

❯ curl https://download.pytorch.org/whl/cu118/wheel
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>2KHYSPNC38BWED53</RequestId><HostId>ZeNiFBKyzFyAMNNKZisld1Oxq9ZnHyJ9oOroNvEfZKp6iibw+ma7UpFTmg5Fs5EFZ//XafwMZ3k=</HostId></Error>%

charliermarsh avatar Oct 18 '24 18:10 charliermarsh

You probably need torchaudio==2.0.0+cu118 and the same for torchvision and torch.

That seems to work. And it is necessary because of the pytorch bug? Because in theory pip should be able to find that version itself automatically, right? Can uv deal with the incorrectly returned 403 anyway?

Leon0402 avatar Oct 18 '24 18:10 Leon0402

@charliermarsh My bad, actually doesn't work.

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

Same error as before.

Leon0402 avatar Oct 18 '24 19:10 Leon0402

@charliermarsh My bad, actually doesn't work.

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

Same error as before.

@Leon0402 Use --extra-index-url instead of --index-url

uv pip install torch==2.0.0+cu118 torchvision==0.15.0+cu118 torchaudio==2.0.0+cu118 --extra-index-url https://download.pytorch.org/whl/cu118

There are actually differences between uv and pip in terms of index resolution. I think the problem here. It's not a bug, but they're just not exactly the same. https://docs.astral.sh/uv/pip/compatibility/#packages-that-exist-on-multiple-indexes

Edit: It doesn't seem to work, it's not very stable.

FishAlchemist avatar Oct 18 '24 19:10 FishAlchemist

@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).

Leon0402 avatar Oct 21 '24 09:10 Leon0402

@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 avatar Oct 21 '24 09:10 FishAlchemist

@FishAlchemist Love it! I'll have a look later.

Leon0402 avatar Oct 21 '24 09:10 Leon0402

None of those worked for me.

Solution:

import os
os.environ["OMP_NUM_THREADS"] = "1"

smortezah avatar Nov 19 '24 11:11 smortezah

These should now be fixed in the latest releases.

charliermarsh avatar Dec 27 '24 14:12 charliermarsh

I am still encountering this issue.

Using uv 0.5.25 and Python 3.10.13 on an amd64 ubuntu machine, calling

uv pip install "torch==1.12.0+cu113" "torchvision==0.13.0+cu113" "pytorch-lightning==1.9.5" --extra-index-url https://download.pytorch.org/whl/

fails with

× No solution found when resolving dependencies:
  ╰─▶ Because torch==1.12.0+cu113 has no wheels with a matching Python ABI
      tag (e.g., `cp311`) and you require torch==1.12.0+cu113, we can conclude
      that your requirements are unsatisfiable.

      hint: `torch` was found on https://download.pytorch.org/whl/, but not
      at the requested version (torch==1.12.0+cu113). A compatible version
      may be available on a subsequent index (e.g., https://pypi.org/simple).
      By default, uv will only consider versions that are published on the
      first index that contains a given package, to avoid dependency confusion
      attacks. If all indexes are equally trusted, use `--index-strategy
      unsafe-best-match` to consider all versions from all indexes, regardless
      of the order in which they were defined.

      hint: You require CPython 3.11 (`cp311`), but we only found wheels for
      `torch` (v1.12.0+cu113) with the following Python ABI tags: `cp37m`,
      `cp38`, `cp39`, `cp310`

Note that both hints are confusing and don't help debugging the problem. The second one is even misleading, as the command is run on python Python 3.10.13

Using exactly the same command, but without the uv at the beginning succeeds.

Using uv 0.2.25 encounters the same error, but only prints the first part of the error message, not the 2 additional sections.

Up until 3 weeks ago, the uv commands were successful. Since then, nothing in our code change. Thus the reason for the error occurring is probably a change in the way pytorch provides its wheel files, uncovering a differing behaviour between pip and uv.

MalteEbner avatar Jan 29 '25 18:01 MalteEbner

If you're seeing those hints, then uv is definitely using Python 3.11. How are you determining that it's using Python 3.10?

charliermarsh avatar Jan 29 '25 18:01 charliermarsh

The second one is even misleading, as the command is run on python Python 3.10.13

What do you mean by this?

Can you share verbose logs?

zanieb avatar Jan 29 '25 18:01 zanieb

If you're seeing those hints, then uv is definitely using Python 3.11. How are you determining that it's using Python 3.10?

I am running python --version directly before the uv command.

I am running it in GitHub CI inside a freshly created venv created with uv that is then populated with some packages. This steps then overwrites some of the packages to other versions. The full commands of this step are:

uv pip install "numpy<1.24"
uv --version
python --version
uv pip install "torch==1.12.0+cu113" "torchvision==0.13.0+cu113" "pytorch-lightning==1.9.5" --extra-index-url https://download.pytorch.org/whl/cu113

The output is

  shell: /usr/bin/bash -e {0}
  env:
    GIT_REF: master
    pythonLocation: /datasets/actions-runner/core_gpu_runner_05/hostedtoolcache/Python/3.10.13/x64
    PKG_CONFIG_PATH: /datasets/actions-runner/core_gpu_runner_05/hostedtoolcache/Python/3.10.13/x64/lib/pkgconfig
    Python_ROOT_DIR: /datasets/actions-runner/core_gpu_runner_05/hostedtoolcache/Python/3.10.13/x64
    Python2_ROOT_DIR: /datasets/actions-runner/core_gpu_runner_05/hostedtoolcache/Python/3.10.13/x64
    Python3_ROOT_DIR: /datasets/actions-runner/core_gpu_runner_05/hostedtoolcache/Python/3.10.13/x64
    LD_LIBRARY_PATH: /datasets/actions-runner/core_gpu_runner_05/hostedtoolcache/Python/3.10.13/x64/lib
    PATH: /datasets/actions-runner/core_gpu_runner_05/_work/lightly-core/lightly-core/.venv/bin:/datasets/actions-runner/core_gpu_runner_05/hostedtoolcache/Python/3.10.13/x64/bin:/datasets/actions-runner/core_gpu_runner_05/hostedtoolcache/Python/3.10.13/x64:/home/lightly/.local/bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/lightly/.cargo/bin:/home/lightly/condor/bin:/home/lightly/condor/sbin:/home/lightly/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Resolved 1 package in 5ms
Uninstalled 1 package in 13ms
Installed 1 package in 24ms
 - numpy==2.0.1
 + numpy==1.23.5
uv 0.5.25
Python 3.10.13
  × No solution found when resolving dependencies:
  ╰─▶ Because torch==1.12.0+cu113 has no wheels with a matching Python ABI
      tag (e.g., `cp311`) and you require torch==1.12.0+cu113, we can conclude
      that your requirements are unsatisfiable.

      hint: `torch` was found on https://download.pytorch.org/whl/, but not
      at the requested version (torch==1.12.0+cu113). A compatible version
      may be available on a subsequent index (e.g., https://pypi.org/simple).
      By default, uv will only consider versions that are published on the
      first index that contains a given package, to avoid dependency confusion
      attacks. If all indexes are equally trusted, use `--index-strategy
      unsafe-best-match` to consider all versions from all indexes, regardless
      of the order in which they were defined.

      hint: You require CPython 3.11 (`cp311`), but we only found wheels for
      `torch` (v1.12.0+cu113) with the following Python ABI tags: `cp37m`,
      `cp38`, `cp39`, `cp310`
Error: Process completed with exit code 1.

The reported available packages are correct, see the torch wheels at https://download.pytorch.org/whl/torch/

Image

MalteEbner avatar Jan 30 '25 07:01 MalteEbner

Have you tried uv pip install --python 3.10 ...? It's not necessarily the case that the python that you get from python --version is the exact same Python that uv would use.

charliermarsh avatar Jan 30 '25 13:01 charliermarsh

Have you tried uv pip install --python 3.10 ...? It's not necessarily the case that the python that you get from python --version is the exact same Python that uv would use.

I tried which python && uv pip install --python 3.10 "torch==1.12.0+cu113" "torchvision==0.13.0+cu113" "pytorch-lightning==1.9.5" --extra-index-url https://download.pytorch.org/whl/cu113 and got

/datasets/actions-runner/core_gpu_runner_03/hostedtoolcache/Python/3.10.13/x64/bin/python
error: Failed to inspect Python interpreter from search path at `/usr/bin/python`
  Caused by: Can't use Python at `/usr/bin/python`
  Caused by: Python executable does not support `-I` flag. Please use Python 3.8 or newer.

MalteEbner avatar Jan 31 '25 09:01 MalteEbner

Sorry, it seems like something really weird is going on here. Can you share full verbose logs for that last command?

zanieb avatar Jan 31 '25 14:01 zanieb

And just to clarify, since I asked for the verbose logs before already, that's

uv pip install --verbose --python 3.10 "torch==1.12.0+cu113" "torchvision==0.13.0+cu113" "pytorch-lightning==1.9.5" --extra-index-url https://download.pytorch.org/whl/cu113

zanieb avatar Jan 31 '25 14:01 zanieb

If this is in GitHub Actions, it'd also be really helpful to share the code / a run in a public repository so we can debug what's going on.

zanieb avatar Jan 31 '25 14:01 zanieb

Sorry, it seems like something really weird is going on here. Can you share full verbose logs for that last command?

Thanks for helping me debug it! The logs were

DEBUG uv 0.5.25
DEBUG Searching for Python 3.10 in virtual environments
DEBUG Found `cpython-3.11.11-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/_work/lightly-core/lightly-core/.venv/bin/python3` (virtual environment)
DEBUG Skipping interpreter at `.venv/bin/python3` from virtual environment: does not satisfy request `3.10`
DEBUG Found `cpython-3.10.13-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python3.10` (search path)
DEBUG Ignoring Python interpreter at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python3.10`: system interpreter not explicitly requested
DEBUG Found `cpython-3.10.13-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python3` (search path)
DEBUG Ignoring Python interpreter at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python3`: system interpreter not explicitly requested
DEBUG Found `cpython-3.10.13-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python` (search path)
DEBUG Ignoring Python interpreter at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python`: system interpreter not explicitly requested
DEBUG Found `cpython-3.10.13-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/python` (search path)
DEBUG Ignoring Python interpreter at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/python`: system interpreter not explicitly requested
DEBUG Found `cpython-3.11.11-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/_work/lightly-core/lightly-core/.venv/bin/python3` (search path)
DEBUG Skipping interpreter at `.venv/bin/python3` from search path: does not satisfy request `3.10`
DEBUG Found `cpython-3.11.11-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/_work/lightly-core/lightly-core/.venv/bin/python` (search path)
DEBUG Skipping interpreter at `.venv/bin/python` from search path: does not satisfy request `3.10`
DEBUG Found `cpython-3.10.13-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python3.10` (search path)
DEBUG Ignoring Python interpreter at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python3.10`: system interpreter not explicitly requested
DEBUG Found `cpython-3.10.13-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python3` (search path)
DEBUG Ignoring Python interpreter at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python3`: system interpreter not explicitly requested
DEBUG Found `cpython-3.10.13-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python` (search path)
DEBUG Ignoring Python interpreter at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/bin/python`: system interpreter not explicitly requested
DEBUG Found `cpython-3.10.13-linux-x86_64-gnu` at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/python` (search path)
DEBUG Ignoring Python interpreter at `/datasets/actions-runner/core_gpu_runner_01/hostedtoolcache/Python/3.10.13/x64/python`: system interpreter not explicitly requested
DEBUG Found `cpython-3.10.14-linux-x86_64-gnu` at `/usr/bin/python3.10` (search path)
DEBUG Ignoring Python interpreter at `/usr/bin/python3.10`: system interpreter not explicitly requested
DEBUG Found `cpython-3.8.10-linux-x86_64-gnu` at `/usr/bin/python3` (search path)
DEBUG Ignoring Python interpreter at `/usr/bin/python3`: system interpreter not explicitly requested
DEBUG Failed to inspect Python interpreter from search path at `/usr/bin/python` 
DEBUG Skipping bad interpreter at /usr/bin/python from search path: Python executable does not support `-I` flag. Please use Python 3.8 or newer.
DEBUG Found `cpython-3.10.14-linux-x86_64-gnu` at `/bin/python3.10` (search path)
DEBUG Ignoring Python interpreter at `/bin/python3.10`: system interpreter not explicitly requested
DEBUG Found `cpython-3.8.10-linux-x86_64-gnu` at `/bin/python3` (search path)
DEBUG Ignoring Python interpreter at `/bin/python3`: system interpreter not explicitly requested
DEBUG Failed to inspect Python interpreter from search path at `/bin/python` 
DEBUG Skipping bad interpreter at /bin/python from search path: Python executable does not support `-I` flag. Please use Python 3.8 or newer.
error: Failed to inspect Python interpreter from search path at `/usr/bin/python`
  Caused by: Can't use Python at `/usr/bin/python`
  Caused by: Python executable does not support `-I` flag. Please use Python 3.8 or newer.

This helped find out the error: When creating the .venv with uv, it did not take the python version installed by the GitHub action (3.10), but a newer version found on the system (3.11). I fixed this by not installing python via GitHub action at all, but by specifying the version when calling uv venv .venv. See the update:

Image

If this is in GitHub Actions, it'd also be really helpful to share the code / a run in a public repository so we can debug what's going on.

This is a GitHub action on a custom self-hosted GitHub runner that is inside a docker container.

MalteEbner avatar Jan 31 '25 16:01 MalteEbner

Great thank you! I will open an issue to track an improvement here.

zanieb avatar Jan 31 '25 18:01 zanieb