uv-python
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePython Package Management with uv
使用uv进行Python包管理
Use exclusively. Never use pip, pip-tools, poetry, virtualenv or conda for dependency management.
uv仅使用进行操作。在依赖管理中绝不要使用pip、pip-tools、poetry、virtualenv或conda。
uvProject (has pyproject.toml
or requirements.txt
)
pyproject.tomlrequirements.txt项目场景(包含pyproject.toml
或requirements.txt
)
pyproject.tomlrequirements.txt- Init new project:
uv init - Add dep:
uv add <package> - Remove dep:
uv remove <package> - Sync env:
uv sync - Run script:
uv run <script>.py
- 初始化新项目:
uv init - 添加依赖:
uv add <package> - 移除依赖:
uv remove <package> - 同步环境:
uv sync - 运行脚本:
uv run <script>.py
Standalone Script (outside a project, or temporary use but need keep the file)
独立脚本场景(项目外,或需保留文件的临时使用场景)
Use PEP 723 inline metadata to declare dependencies inside the script:
python
undefined使用PEP 723内联元数据在脚本中声明依赖:
python
undefined/// script
/// script
requires-python = ">=3.12"
requires-python = ">=3.12"
dependencies = [
dependencies = [
"requests",
"requests",
]
]
///
///
- Or add dep: `uv add <package> --script <script>.py`
- Or remove dep: `uv remove <package> --script <script>.py`
- Run: `uv run <script>.py`
- 或添加依赖:`uv add <package> --script <script>.py`
- 或移除依赖:`uv remove <package> --script <script>.py`
- 运行脚本:`uv run <script>.py`One-Off Code (no file saved, temporary execution)
一次性代码场景(不保存文件,临时执行)
bash
uv run - <<'EOF'
<script>
EOFbash
uv run - <<'EOF'
<script>
EOFOther Commands
其他命令
- Run a tool temporarily:
uvx <tool> - Install a tool globally:
uv tool install <tool> - Run with specific Python version: uv run --python 3.10 <script>.py
- 临时运行工具:
uvx <tool> - 全局安装工具:
uv tool install <tool> - 使用特定Python版本运行:uv run --python 3.10 <script>.py