Python venv
Use this skill when the task requires writing and running Python code with isolated dependencies.
Core rule
exec calls are stateless across invocations. Do not rely on source .venv/bin/activate persisting between calls.
Always call the interpreter and pip directly from the venv path.
Standard workflow
- •Create a project-local environment:
bash
python3 -m venv .venv
- •Install dependencies:
bash
.venv/bin/python -m pip install --upgrade pip .venv/bin/python -m pip install -r requirements.txt
- •Run scripts:
bash
.venv/bin/python script.py
Recommended execution pattern
When possible, run setup + execution in one command so context is explicit:
bash
python3 -m venv .venv && \ .venv/bin/python -m pip install --upgrade pip && \ .venv/bin/python -m pip install -r requirements.txt && \ .venv/bin/python script.py
File layout
- •Keep scripts in workspace-local paths, for example
scripts/or repo root. - •Keep environment in
.venv/at project root. - •Keep dependency pins in
requirements.txt.
Troubleshooting
- •
python3: command not found: install Python 3 and rerun. - •
No module named pip: recreate venv withpython3 -m venv .venv --upgrade-depsif available. - •Build tool errors on native packages: report the missing system dependency and stop before retry loops.