Guidelines and tools for managing Python virtual environments.
When to Use
- When a skill needs to install Python dependencies
- When executing Python scripts that require an isolated environment
- Avoid polluting the global Python environment
- When multiple projects require different versions of dependencies
Quick Start
# 1. 创建虚拟环境
python scripts/create-venv.py <path> [--python <version>]
# 2. 激活虚拟环境
source scripts/activate-venv.sh <path>
3. Install dependencies
pip install -r requirements.txt
## 工作流程
1. **检查现有虚拟环境**
- 检查 `.venv/` 或 `venv/` 目录是否存在
- 检查 `.venv_path` 文件中的路径
2. **创建虚拟环境(如需要)**
```bash
python scripts/create-venv.py <path>
-
Activate the virtual environment
source scripts/activate-venv.sh <path> # 或使用 Python API python scripts/activate-venv.py --activate <path> -
Execute commands in the virtual environment
- All pip install commands should be executed after activation
- All Python scripts should be run after activation
-
Cleanup (optional)
python scripts/cleanup-venv.py <path>
Reference Files
| File | Purpose |
|---|---|
scripts/create-venv.py |
Create a new virtual environment |
scripts/activate-venv.py |
Activate the virtual environment (Python API) |
scripts/activate-venv.sh |
Activate the virtual environment (Shell script) |
scripts/cleanup-venv.py |
Clean up/delete the virtual environment |
references/venv-guide.md |
Best practices for virtual environment management |
references/common-issues.md |
Common problem solutions |