setup-python

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Python 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

快速设置检查清单

  1. ✅ Verify Python 3.10+
  2. ✅ Install UV (required package manager)
  3. ✅ Setup virtual environment with UV
  4. ✅ Install dependencies
  5. ✅ Setup Ruff (linting + formatting)
  6. ✅ Setup MyPy (type checking)
  7. ✅ Setup pytest (testing)
  8. ✅ Setup pre-commit hooks
  9. ✅ Verify imports and dependencies
  10. ✅ Run quality checks
  11. ✅ Run tests
  12. ✅ Verify environment reproducibility
For detailed step-by-step instructions with UV commands and troubleshooting, see
references/DETAILED-WORKFLOW.md
.
  1. ✅ 验证Python 3.10+版本
  2. ✅ 安装UV(必需的包管理器)
  3. ✅ 使用UV设置虚拟环境
  4. ✅ 安装依赖项
  5. ✅ 设置Ruff(代码检查 + 格式化)
  6. ✅ 设置MyPy(类型检查)
  7. ✅ 设置pytest(测试)
  8. ✅ 设置pre-commit钩子
  9. ✅ 验证导入和依赖项
  10. ✅ 运行质量检查
  11. ✅ 运行测试
  12. ✅ 验证环境可复现性
如需包含UV命令和故障排除的详细分步说明,请查看
references/DETAILED-WORKFLOW.md

Troubleshooting

故障排除

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 | sh

Then restart shell or source profile

然后重启shell或加载配置文件

undefined
undefined

Issue: "No Python found"

问题:"No Python found"

Solution: Install Python with UV
bash
uv python install 3.12
解决方案:使用UV安装Python
bash
uv python install 3.12

Issue: "Resolution failed"

问题:"Resolution failed"

Solution: Dependency conflict
bash
undefined
解决方案:依赖冲突
bash
undefined

Show 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 .
undefined
uv pip install --resolution=lowest .
undefined

Issue: "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

最佳实践

  1. Always use UV - Never use pip directly
  2. Use pyproject.toml - Modern Python standard
  3. Use Ruff - Replaces flake8, black, isort (faster)
  4. Lock dependencies - Use
    uv lock
    or
    uv pip compile
  5. Pin Python version - Use
    uv python pin
  6. Enable mypy strict mode - Catch type errors early
  7. Use pre-commit hooks - Automate checks
  8. Target 90%+ coverage - Comprehensive testing

  1. 始终使用UV - 切勿直接使用pip
  2. 使用pyproject.toml - 现代Python标准
  3. 使用Ruff - 替代flake8、black、isort(速度更快)
  4. 锁定依赖项 - 使用
    uv lock
    uv pip compile
  5. 固定Python版本 - 使用
    uv python pin
  6. 启用mypy严格模式 - 尽早捕获类型错误
  7. 使用pre-commit钩子 - 自动化检查
  8. 目标覆盖率90%以上 - 全面测试

Migration from pip

从pip迁移

If you have an existing project using pip:
bash
undefined
如果您的现有项目使用pip:
bash
undefined

Create 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:
  • quality-check
    - When checking Python code quality
  • run-tests
    - When running Python tests
本技能可能会被以下技能调用:
  • quality-check
    - 检查Python代码质量时
  • run-tests
    - 运行Python测试时