install

1
2
3
4
5
6
7
8
9
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# On Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
scoop install uv

# With pip (if you must, not the preferred way though)
pip install uv

set UV_CACHE_DIR

By default, the cache is stored in $XDG_CACHE_HOME/uv or $HOME/.cache/uv on Unix and %LOCALAPPDATA%\uv\cache on Windows.

setup a new project

init

1
2
uv init  uv_template
cd uv_template

the folder structure:

1
2
3
4
5
6
7
❯ dust
  0B   ┌── README.md      │█                                                                                      │   0%
 57B   │   ┌── __init__.py│█████████████████                                                                      │  20%
 57B   │ ┌─┴ uv_template  │█████████████████                                                                      │  20%
 57B   ├─┴ src            │█████████████████                                                                      │  20%
232B   ├── pyproject.toml │██████████████████████████████████████████████████████████████████████                 │  80%
289B ┌─┴ .                │██████████████████████████████████████████████████████████████████████████████████████ │ 100%

the pyproject.toml file which will look like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
❯ cat .\pyproject.toml
[project]
name = "uv-template"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = []

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

setup virtualenv

install python with specified version

1
uv python  install 3.10.6

create virtual environment

1
uv venv --python 3.10.6

packages

install

1
uv add  tqdm 

after add tqdm, the pyproject.toml file which will look like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
❯ cat  .\pyproject.toml
[project]
name = "uv-template"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
    "tqdm>=4.66.5",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

turn pyproject.toml to requirements.txt

1
uv pip compile pyproject.toml -o requirements.txt

sync

1
un pip sync 
1
uv sync -p 3.12
1
uv pip sync requirements.txt

reference

uv cli