uv: Installation of torch from pytorch CPU index fails with 'no wheels are available with a matching Python ABI'
- A minimal code snippet that reproduces the bug.
uv pip install --verbose --index-url https://download.pytorch.org/whl/cpu torch torchvision torchaudio
- The command you invoked (e.g.,
uv pip sync requirements.txt), ideally including the--verboseflag.
$ docker run --rm -ti python:3.12 /bin/bash
root@4d525f9218ee:/# curl -LsSf https://astral.sh/uv/install.sh | sh
downloading uv 0.1.40 x86_64-unknown-linux-gnu
installing to /root/.cargo/bin
uv
everything's installed!
To add $HOME/.cargo/bin to your PATH, either restart your shell or run:
source $HOME/.cargo/env (sh, bash, zsh)
source $HOME/.cargo/env.fish (fish)
root@4d525f9218ee:/# . ~/.cargo/env
root@4d525f9218ee:/# uv venv
Using Python 3.12.3 interpreter at: usr/local/bin/python3
Creating virtualenv at: .venv
root@4d525f9218ee:/# . .venv/bin/activate
(.venv) root@4d525f9218ee:/# uv --version
uv 0.1.40
(.venv) root@4d525f9218ee:/# uv pip install --verbose --index-url https://download.pytorch.org/whl/cpu torch torchvision torchaudio &> uv_install.txt
(.venv) root@4d525f9218ee:/# uv pip list # nothing
(.venv) root@4d525f9218ee:/# uv pip install pip
Resolved 1 package in 198ms
Downloaded 1 package in 219ms
Installed 1 package in 10ms
+ pip==24.0
(.venv) root@4d525f9218ee:/# python -m pip install --verbose --index-url https://download.pytorch.org/whl/cpu torch torchvision torchaudio &> pip_install.txt
(.venv) root@4d525f9218ee:/# python -m pip list # expected result
Package Version
----------------- ----------
filelock 3.13.1
fsspec 2024.2.0
Jinja2 3.1.3
MarkupSafe 2.1.5
mpmath 1.3.0
networkx 3.2.1
numpy 1.26.3
pillow 10.2.0
pip 24.0
sympy 1.12
torch 2.3.0+cpu
torchaudio 2.3.0+cpu
torchvision 0.18.0+cpu
typing_extensions 4.9.0
(.venv) root@4d525f9218ee:/# deactivate
root@4d525f9218ee:/# rm -rf .venv
root@4d525f9218ee:/# uv venv && . .venv/bin/activate
Using Python 3.12.3 interpreter at: usr/local/bin/python3
Creating virtualenv at: .venv
(.venv) root@4d525f9218ee:/# uv pip install --verbose torch torchvision torchaudio &> uv_pypi_install.txt
(.venv) root@4d525f9218ee:/# uv pip list # install works, but want the cpu version instead of this
Package Version
------------------------ ----------
filelock 3.14.0
fsspec 2024.3.1
jinja2 3.1.4
markupsafe 2.1.5
mpmath 1.3.0
networkx 3.3
numpy 1.26.4
nvidia-cublas-cu12 12.1.3.1
nvidia-cuda-cupti-cu12 12.1.105
nvidia-cuda-nvrtc-cu12 12.1.105
nvidia-cuda-runtime-cu12 12.1.105
nvidia-cudnn-cu12 8.9.2.26
nvidia-cufft-cu12 11.0.2.54
nvidia-curand-cu12 10.3.2.106
nvidia-cusolver-cu12 11.4.5.107
nvidia-cusparse-cu12 12.1.0.106
nvidia-nccl-cu12 2.20.5
nvidia-nvjitlink-cu12 12.4.127
nvidia-nvtx-cu12 12.1.105
pillow 10.3.0
sympy 1.12
torch 2.3.0
torchaudio 2.3.0
torchvision 0.18.0
typing-extensions 4.11.0
(.venv) root@4d525f9218ee:/#
- The current uv platform.
Linux, though applies across platforms.
- The current uv version (
uv --version).
uv 0.1.40
Related Issues
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 17 (9 by maintainers)
Streamlit uses uv to install dependencies from a requirements.txt file which caused our app to fail. I managed to work around it by pinning the version number as suggested here.
You can avoid the extra specificity on those depending on
torch, but due to+cpuyou can’t use a semver range (like>=2.0.0) withtorch:NOTE: ARM64 needs to omit the
+cpuor equivalent due to upstream inconsistency with packaging. That may be resolved in future as PyTorch maintainers are open to contributions to drop the+cpulocal identifier.TLDR(unreliable, see gotcha)TL;DR:
Either:+cpu,+cu121, etc) suffix to each package (which mandates an explicit version?), and they must be installed all together to resolve correctly it seems. (UPDATE: Only the top-level dependency needs the suffix that others would depend upon)Use PyPi as the primary index, with PyTorch as your extra index (which🎉uvwill prioritize packages from), then to ensuretorchwithout a local identifier is resolvable from PyPi index you’ll need--index-strategy unsafe-first-match, and it’ll circle back to the PyTorch variant being successfully resolvedNOTE: If you attempt to use
>=for resolution, you must quote wrap it to avoid shell redirection (>) which creates a file (eg:=0.0.0+cpu);uvwill not be aware of this to raise an error (like it would when you use quote wrapping):Resolution gotcha (cache affects selection?)
UPDATE: I am mistaken with the
--index-strategyapproach to resolvetorch. Whileuvwould happily resolve with this approach, the actualtorchpackage selected seems to be chosen based on local cache as well:As can be seen above different resolution due to previous actions, now the cuda variant from PyTorch was installed instead of the PyPi torch pacakge
Original response
So that installed with
torchresolved totorch 2.3.0+cu121, yet when trying to addtorchaudioor the more specifictorchaudio==2.3.0+cu121it fails:Meanwhile, like with the suggested
+cpufix before my comment, the equivalent does resolve correctly:So there is some issue there with
uvresolvingtorch?torch==2.3.0+cu121, it can only resolve with the explicittorchaudio==2.3.0+cu121at the same time, not as a 2nd install.torch torchaudiowithout the+cu121suffix fails to resolve.Definitely seems like some inconsistency with
uv?EDIT: Oh I see the linked issue references this gotcha (local identifiers support) with
uv, and specifically cites PyTorch as an example.So by setting it as an extra index URL instead, the PyTorch index will be preferred by
uv, but you need theunsafe-first-matchstrategy so that it can find/resolve thetorchpackage available at PyPi (since PyTorch doesn’t provide it for an index focused on only that “local identifier” variant), thenuvwill resolve it successfully and still prefer the PyTorch package anyway 🤷♂️If you of course remove the extra index URL for PyTorch, then it’ll resolve the standard
torch==2.3.0+torchaudio==2.3.0packages at PyPi and install those like you’d expect.As long as the package is known to exist at PyTorch, it should always be preferred this way, even if there were a malicious version on PyPi from what I understand? Once
uvsupports the feature to lock the index to PyTorch for these specific packages that may help, but I assume that wouldn’t help drop the index strategy (it may even not be able to resolve the PyPitorchpackage just so it can circle back to PyTorch?).Probably better to be explicit about the local identifier though, I am new to Python and was referencing someone elses
pip installwhere the local identifier was implicit from the--extra-index-url(a variable during builds to support the PyTorch variants).I haven’t really dug into it. My guess is it relates to some unclear decisions around how PyTorch chooses to publish their wheels (e.g., some variants include
+cpuwhile others do not).Can you try instead using
uv pip install --verbose --index-url https://download.pytorch.org/whl/cpu torch==2.3.0+cpu torchvision==0.18.0+cpu torchaudio==2.3.0+cpu? I can’t reproduce this on ARM, but I think it differs on ARM vs. x86.Ah ok, no prob. Mostly was wondering if it was “obviously a regression” from today’s release.