一个用 Rust 编写的极快的 Python 包和项目管理工具
curl -LsSf https://astral.sh/uv/install.sh | sh
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# pip
pip install uv
# pipx
pipx install uv
# 创建一个目录作为项目的根目录
uv init project_name
# 将当前目录作为项目的根目录
uv init
.
├── .venv # 项目的虚拟环境
│ ├── bin
│ ├── lib
│ └── pyvenv.cfg
├── .python-version # 项目的 Python 版本
├── README.md
├── main.py
├── pyproject.toml # 项目的元数据
└── uv.lock # 项目的锁定文件, 用于锁定依赖版本,不应手动编辑
uv add requests
# 指定版本
uv add 'requests==2.28.1'
# 指定来源
uv add git+https://github.com/psf/requests
requirements.txt
迁移uv add -r requirements.txt
uv remove requests
uv lock --upgrade-package requests
指定脚本运行
uv run main.py
指定Python版本运行
uv run --python 3.10 main.py
uv build
构建结果存储在dist
目录下