Create, manage, and validate Python virtual environments. Use for project isolation and dependency management.
Single responsibility: Create and manage Python virtual environments for project isolation. (BP-4)
Before executing, VERIFY:
DO NOT create venv without confirming Python version.
ASK USER instead of guessing when:
NEVER delete existing venv without confirmation.
| Context Type | Included | Excluded |
|---|---|---|
| RELEVANT | Python version, project deps, venv path | Application code |
| PERIPHERAL | CI/CD requirements | Test configurations |
| DISTRACTOR | Deployment configs | Other language envs |
# Available Python versions
which python3
python3 --version
# Check for existing venv
ls -la venv/ 2>/dev/null || ls -la .venv/ 2>/dev/null || echo "No venv found"
# Current active environment
echo "VIRTUAL_ENV: $VIRTUAL_ENV"
# Standard creation
python3 -m venv venv
# With specific Python version
python3.11 -m venv venv
# With system packages access
python3 -m venv venv --system-site-packages
# Verify creation
ls -la venv/bin/python
# Activate
source venv/bin/activate
# Upgrade pip
pip install --upgrade pip
# Install from requirements.txt
pip install -r requirements.txt
# Or from pyproject.toml
pip install -e .
# Development dependencies
pip install -r requirements-dev.txt
# List installed packages
pip list
# Check for missing deps
pip check
# Export current state
pip freeze > requirements-lock.txt
On error:
venv creation failed ā Check Python installationpip install failed ā Check network, package availabilityactivation failed ā Check shell compatibilitydependency conflict ā Use pip-tools or poetryRollback command:
rm -rf venv && python3 -m venv venv
State saved to: .aiwg/working/checkpoints/venv-manager/
checkpoints/venv-manager/
āāā python_version.txt # Python used
āāā pip_freeze.txt # Installed packages
āāā creation_log.txt # Creation output
āāā validation_status.json # Health check results
| Command | Purpose |
|---|---|
python3 -m venv venv |
Create venv |
source venv/bin/activate |
Activate (bash/zsh) |
venv\Scripts\activate |
Activate (Windows) |
deactivate |
Deactivate |
pip freeze > requirements.txt |
Export deps |
pip install -r requirements.txt |
Install deps |
venv/ or .venv/ consistently.gitignorepip freeze or pip-tools