setup-python
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePython Development Setup Skill
Python开发环境搭建技能
Purpose
用途
Quickly set up and verify a Python development environment using UV for fast, reliable dependency management.
使用UV快速搭建并验证Python开发环境,实现快速、可靠的依赖管理。
CRITICAL: Always Use UV
重要提示:始终使用UV
NEVER use pip directly. ALWAYS use UV for Python dependency management.
UV is 10-100x faster than pip and provides:
- Deterministic dependency resolution
- Lockfile support
- Virtual environment management
- Drop-in pip replacement
切勿直接使用pip。请始终使用UV进行Python依赖管理。
UV的速度比pip快10-100倍,并提供以下功能:
- 确定性依赖解析
- 锁文件支持
- 虚拟环境管理
- 可直接替代pip
Workflow
工作流程
Quick Setup Checklist
快速设置检查清单
- ✅ Verify Python 3.10+
- ✅ Install UV (required package manager)
- ✅ Setup virtual environment with UV
- ✅ Install dependencies
- ✅ Setup Ruff (linting + formatting)
- ✅ Setup MyPy (type checking)
- ✅ Setup pytest (testing)
- ✅ Setup pre-commit hooks
- ✅ Verify imports and dependencies
- ✅ Run quality checks
- ✅ Run tests
- ✅ Verify environment reproducibility
For detailed step-by-step instructions with UV commands and troubleshooting, see .
references/DETAILED-WORKFLOW.md- ✅ 验证Python 3.10+版本
- ✅ 安装UV(必需的包管理器)
- ✅ 使用UV设置虚拟环境
- ✅ 安装依赖项
- ✅ 设置Ruff(代码检查 + 格式化)
- ✅ 设置MyPy(类型检查)
- ✅ 设置pytest(测试)
- ✅ 设置pre-commit钩子
- ✅ 验证导入和依赖项
- ✅ 运行质量检查
- ✅ 运行测试
- ✅ 验证环境可复现性
如需包含UV命令和故障排除的详细分步说明,请查看。
references/DETAILED-WORKFLOW.mdTroubleshooting
故障排除
Issue: "uv: command not found"
问题:"uv: command not found"
Solution: UV not installed
bash
curl -LsSf https://astral.sh/uv/install.sh | sh解决方案:未安装UV
bash
curl -LsSf https://astral.sh/uv/install.sh | shThen restart shell or source profile
然后重启shell或加载配置文件
undefinedundefinedIssue: "No Python found"
问题:"No Python found"
Solution: Install Python with UV
bash
uv python install 3.12解决方案:使用UV安装Python
bash
uv python install 3.12Issue: "Resolution failed"
问题:"Resolution failed"
Solution: Dependency conflict
bash
undefined解决方案:依赖冲突
bash
undefinedShow what's conflicting
查看冲突内容
uv pip install --dry-run -r requirements.txt
uv pip install --dry-run -r requirements.txt
Try with looser constraints
尝试使用更宽松的约束
uv pip install --resolution=lowest .
undefineduv pip install --resolution=lowest .
undefinedIssue: "ModuleNotFoundError: No module named 'X'"
问题:"ModuleNotFoundError: No module named 'X'"
Solution: Dependency not installed
bash
uv pip install -e ".[dev]"解决方案:未安装依赖项
bash
uv pip install -e ".[dev]"or
或
uv pip install <module-name>
---uv pip install <module-name>
---Best Practices
最佳实践
- Always use UV - Never use pip directly
- Use pyproject.toml - Modern Python standard
- Use Ruff - Replaces flake8, black, isort (faster)
- Lock dependencies - Use or
uv lockuv pip compile - Pin Python version - Use
uv python pin - Enable mypy strict mode - Catch type errors early
- Use pre-commit hooks - Automate checks
- Target 90%+ coverage - Comprehensive testing
- 始终使用UV - 切勿直接使用pip
- 使用pyproject.toml - 现代Python标准
- 使用Ruff - 替代flake8、black、isort(速度更快)
- 锁定依赖项 - 使用或
uv lockuv pip compile - 固定Python版本 - 使用
uv python pin - 启用mypy严格模式 - 尽早捕获类型错误
- 使用pre-commit钩子 - 自动化检查
- 目标覆盖率90%以上 - 全面测试
Migration from pip
从pip迁移
If you have an existing project using pip:
bash
undefined如果您的现有项目使用pip:
bash
undefinedCreate new venv with UV
使用UV创建新的虚拟环境
rm -rf venv .venv
uv venv
rm -rf venv .venv
uv venv
Activate
激活虚拟环境
source .venv/bin/activate
source .venv/bin/activate
Install existing requirements
安装现有依赖项
uv pip install -r requirements.txt
uv pip install -r requirements.txt
Generate lock file
生成锁文件
uv pip compile requirements.txt -o requirements.lock
---uv pip compile requirements.txt -o requirements.lock
---Integration with Other Skills
与其他技能集成
This skill may be invoked by:
- - When checking Python code quality
quality-check - - When running Python tests
run-tests
本技能可能会被以下技能调用:
- - 检查Python代码质量时
quality-check - - 运行Python测试时
run-tests