Skip to content

UV

安装

Linux 和 macOS 使用 curl 安装:

bash
curl -LsSf https://astral.sh/uv/install.sh | sh

Windows 使用 powershell 安装:

powershell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

也可以使用 pip 安装:

bash
pip install uv

配置

在 Windows 上 UV 默认缓存在 C 盘,这样会导致安装的包无法使用硬链接,影响效率并无法使用 UV 节省空间的优势,可以将缓存目录设置到工作用的盘符上。例如配置环境变量,将缓存目录设置到 D 盘:

ini
UV_CACHE_DIR=D:\.uv-cache

用例

安装 PyTorch:

toml
dependencies = [
    "torch==2.5.1+cu121",
    "torchaudio==2.5.1+cu121",
    "torchvision==0.20.1+cu121",
]

配置 [tool.uv]

toml
[tool.uv]
index-strategy = "unsafe-best-match"
index-url = "https://pypi.org/simple"
extra-index-url = [
    "https://pypi.org/simple",
    "https://download.pytorch.org/whl/cu121",
]