Skip to content

Latest commit

 

History

History
74 lines (56 loc) · 1.21 KB

uv.md

File metadata and controls

74 lines (56 loc) · 1.21 KB

使用uv做Python 版本管理

UV安装

# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh

echo "export PATH=\"\$PATH:\$HOME/.local/bin\"" >> ~/.zshrc

# 配置中国源
mkdir ~/.config/uv && vim ~/.config/uv/uv.toml

# 写入
[[index]]
url = "https://pypi.mirrors.ustc.edu.cn/simple/"
default = true

初始化项目

uv init test-uv

项目结构

.
├── main.py
├── .venv
├── pyproject.toml  # 是项目配置信息
└── README.md

运行脚本

# 自动关联虚拟环境, 优先使用.venv
uv run main.py 

管理依赖

# 安装指定版本
uv add "flask>=2.0.0"

# 同步所有依赖(包括dev)
uv sync

# 仅同步生产依赖
uv sync --production

# 同步并清理多余包
uv sync --clean

管理Python环境

# 列出可用的Python安装版本
uv python list 

uv python install 3.10 3.11 3.12
uv python install 3.10  pypy@3.10


# 当前环境指定版本
uv python pin 3.11

# 创建虚拟环境
uv venv 

# 下载
uv pip sync docs/requirements.txt

参考资料