Skip to content

Instantly share code, notes, and snippets.

@docPhil99
Last active March 23, 2026 14:40
Show Gist options
  • Select an option

  • Save docPhil99/68a144d298efd796fa0b3b90ca5c11a8 to your computer and use it in GitHub Desktop.

Select an option

Save docPhil99/68a144d298efd796fa0b3b90ca5c11a8 to your computer and use it in GitHub Desktop.
uv basics

Create a project uv init. This create the project files

  • uv venv creates the actual .venv environment.
  • uv venv --python 3.11.6 use specific python version
  • uv add Add a dependency to the project.
    • uv add 'requests==2.31.0' specific version
    • uv add -r requirements.txt add requirements.txt
  • uv remove Remove a dependency from the project.
  • uv sync Sync the project's dependencies with the environment.
  • source .venv/bin/activate activate the environment. Run sync first.

Working with Pytorch and CUDA

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment