Create a project uv init. This create the project files
uv venvcreates the actual .venv environment.uv venv --python 3.11.6use specific python versionuv addAdd a dependency to the project.uv add 'requests==2.31.0'specific versionuv add -r requirements.txtadd requirements.txt
uv removeRemove a dependency from the project.uv syncSync the project's dependencies with the environment.source .venv/bin/activateactivate the environment. Run sync first.
If an old version of torch is needed, check the CUDA requirements: https://pytorch.org/get-started/previous-versions/
I'm going to user 2.1.2 which uses CUDA 11.8. My pyproject.toml file looks like this
[project]
name = "torch_demo"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"torch==2.1.2",
"torchvision==0.16.2",
"torchaudio==2.1.2"
]
[[tool.uv.index]]
name = "pytorch-cu118"
url = "https://download.pytorch.org/whl/cu118"
explicit = true
Note the two mentions of cu118 in the bottom section, for CUDA 11.8. Also requires-python = ">=3.10". This must match the python selected during uv init