python-env
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePython Environment
Python环境管理
Fast Python environment management with uv.
使用uv进行快速Python环境管理。
Quick Commands
快速命令
| Task | Command |
|---|---|
| Create venv | |
| Install package | |
| Install from requirements | |
| Run script | |
| Show installed | |
| 任务 | 命令 |
|---|---|
| 创建虚拟环境 | |
| 安装包 | |
| 从requirements文件安装 | |
| 运行脚本 | |
| 查看已安装包 | |
Virtual Environment
虚拟环境
bash
undefinedbash
undefinedCreate venv (instant)
创建虚拟环境(瞬间完成)
uv venv
uv venv
Create with specific Python
使用指定Python版本创建
uv venv --python 3.11
uv venv --python 3.11
Activate (or use uv run)
激活虚拟环境(或使用uv run)
source .venv/bin/activate # Unix
.venv\Scripts\activate # Windows
undefinedsource .venv/bin/activate # Unix系统
.venv\Scripts\activate # Windows系统
undefinedPackage Installation
包安装
bash
undefinedbash
undefinedSingle package
安装单个包
uv pip install requests
uv pip install requests
Multiple packages
安装多个包
uv pip install flask sqlalchemy pytest
uv pip install flask sqlalchemy pytest
With extras
安装包含额外依赖的包
uv pip install "fastapi[all]"
uv pip install "fastapi[all]"
Version constraints
带版本约束安装
uv pip install "django>=4.0,<5.0"
uv pip install "django>=4.0,<5.0"
Uninstall
卸载包
uv pip uninstall requests
undefineduv pip uninstall requests
undefinedMinimal pyproject.toml
最简pyproject.toml配置
toml
[project]
name = "my-project"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = [
"httpx>=0.25",
"pydantic>=2.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.0",
"ruff>=0.1",
]toml
[project]
name = "my-project"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = [
"httpx>=0.25",
"pydantic>=2.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.0",
"ruff>=0.1",
]Project Setup Checklist
项目设置检查清单
bash
mkdir my-project && cd my-project
uv venvbash
mkdir my-project && cd my-project
uv venvCreate pyproject.toml
创建pyproject.toml文件
uv pip install -e ".[dev]"
uv pip list
undefineduv pip install -e ".[dev]"
uv pip list
undefinedTroubleshooting
故障排除
| Issue | Solution |
|---|---|
| "No Python found" | |
| Wrong Python version | |
| Conflicting deps | |
| Cache issues | |
| 问题 | 解决方案 |
|---|---|
| "未找到Python" | |
| Python版本错误 | |
| 依赖冲突 | |
| 缓存问题 | |
When to Use
使用场景
- Always use uv over pip for speed
- Creating virtual environments
- Installing packages
- Managing dependencies
- Running scripts in project context
- 始终优先使用uv而非pip以提升速度
- 创建虚拟环境
- 安装包
- 管理依赖项
- 在项目上下文中运行脚本
Additional Resources
额外资源
For detailed patterns, load:
- - Full pyproject.toml examples, tool configs
./references/pyproject-patterns.md - - Lock files, workspaces, private packages
./references/dependency-management.md - - PyPI publishing, versioning, CI/CD
./references/publishing.md
如需详细模式,请查看:
- - 完整pyproject.toml示例、工具配置
./references/pyproject-patterns.md - - 锁定文件、工作区、私有包
./references/dependency-management.md - - PyPI发布、版本控制、CI/CD
./references/publishing.md
See Also
相关技能
This is a foundation skill with no prerequisites.
Build on this skill:
- - Type hints for projects
python-typing-patterns - - Testing infrastructure
python-pytest-patterns - - Web API development
python-fastapi-patterns
这是一项基础技能,无前置要求。
可基于此技能拓展:
- - 项目类型提示
python-typing-patterns - - 测试基础设施
python-pytest-patterns - - Web API开发
python-fastapi-patterns