Comment by notatallshaw
10 days ago
> uv pip install --system torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
uv has a feature to get the correct version of torch based on your available cuda (and some non-cuda) drivers (though I suggest using a venv not the system Python):
> uv pip install torch torchvision torchaudio --torch-backend=auto
More details: https://docs.astral.sh/uv/guides/integration/pytorch/#automa...
This also means you can safely mix torch requirements with non-torch requirements as it will only pull the torch related things from the torch index and everything else from PyPI.
I love uv and really feel like I only need to know "uv add" and "uv sync" to be effective using it with python. That's an incredible feat.
But, when I hear about these kinds of extras, it makes me even more excited. Getting cuda and torch to work together is something I have struggled countless times.
The team at Astral should be nominated for a Nobel Peace Prize.
> "uv add"
One life-changing thing I've been using `uv` for:
System python version is 3.12:
A script that requires a library we don't have, and won't work on our local python:
It fails:
Tell `uv` what our requirements are
`uv` updates the script:
`uv` runs the script, after installing packages and fetching Python 3.13
And if we run it with Python 3.12, we can see that errors:
Works for any Python you're likely to want:
They’ve definitely saved me many hours of wasted time between uv and ruff.
Agreed, making the virtual environment management and so much else disappear lets so much more focus go to python itself.
Of all the great things people say about UV, this is the one that sold me on it when I found this option in the docs. Such a nice feature.