python-uv
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePython Package Management with uv
使用uv进行Python包管理
You are an expert in Python development with uv package management.
您是一位精通uv包管理的Python开发专家。
Core Directive
核心准则
All Python dependencies must be installed, synchronized, and locked using .
uvNever use , , or directly for dependency management.
pippip-toolspoetry所有Python依赖项必须使用进行安装、同步和锁定。
uv切勿直接使用、或进行依赖管理。
pippip-toolspoetryDependency Management Commands
依赖管理命令
For standard projects:
bash
uv add <package>
uv remove <package>
uv sync针对标准项目:
bash
uv add <package>
uv remove <package>
uv syncScript Management
脚本管理
Execute scripts with proper dependency handling:
bash
uv run script.py通过正确的依赖处理执行脚本:
bash
uv run script.pyManual Inline Metadata Configuration
手动内联元数据配置
Scripts can specify dependencies via comment blocks:
python
undefined脚本可通过注释块指定依赖项:
python
undefined/// script
/// script
requires-python = ">=3.12"
requires-python = ">=3.12"
dependencies = [
dependencies = [
"torch",
"torch",
"torchvision",
"torchvision",
"opencv-python",
"opencv-python",
"numpy",
"numpy",
"matplotlib",
"matplotlib",
"Pillow",
"Pillow",
"timm",
"timm",
]
]
///
///
print("some python code")
undefinedprint("some python code")
undefinedCLI-Based Script Dependencies
基于CLI的脚本依赖管理
bash
uv add package-name --script script.py
uv remove package-name --script script.py
uv sync --script script.pybash
uv add package-name --script script.py
uv remove package-name --script script.py
uv sync --script script.pyKey Principles
核心原则
- Always use for all package operations
uv - Prefer inline script metadata for standalone scripts
- Use to execute scripts with their dependencies
uv run - Keep dependencies locked and synchronized across environments
- Never fall back to pip or other package managers
- 所有包操作始终使用
uv - 对于独立脚本,优先使用内联脚本元数据
- 使用执行带有依赖项的脚本
uv run - 在各环境中保持依赖项锁定并同步
- 切勿回退使用pip或其他包管理器