@jerryan/pi-pyvenv
v0.1.2
Published
Automatically activate a Python virtual environment for pi coding agents
Maintainers
Readme
@jerryan/pi-pyvenv
A pi extension that transparently ensures every python, python3, pip, and pip3 invocation resolves to a virtual environment — never to the system Python.
Why
Coding agents love running pip install against the system Python. This breaks or pollutes the user's system packages. pi-pyvenv makes this impossible by automatically activating a venv at the process level before the agent starts working.
What it does
On every session start, pi-pyvenv picks a venv in this order:
- Respect existing activation — If
VIRTUAL_ENVis already set (e.g. the user activated a venv in their shell before launching pi), do nothing. - Discover project venv — If
.venv/orvenv/exists in the current working directory, activate that. - Shared fallback venv — Otherwise, activate (or create) a shared user-level venv at
~/.pi/agent/pyvenv/.
The activation mutates process.env.PATH and process.env.VIRTUAL_ENV once at the Node.js process level. All subsequently spawned child processes inherit it automatically — no command rewriting, no spawnHook, no tool interception.
Installation
pi install npm:@jerryan/pi-pyvenvOr install from git:
pi install git:https://github.com/JerryAZR/pi-pyvenv.gitThen restart pi or run /reload.
Commands
| Command | Description |
|---|---|
| /pyvenv status | Show the currently active venv |
| /pyvenv recreate | Delete and rebuild the shared fallback venv |
What it is NOT
This extension is not a project-level venv manager. It does not:
- Create
.venv/in your project directory - Switch venvs when you change directories
- Handle
requirements.txt,pyproject.toml, or lockfiles - Wrap Conda, Poetry,
uv, orpipenv
If you are working on a real Python project, create your own .venv/ and pi-pyvenv will discover and use it automatically.
Design decisions
- No system prompt injection — The agent does not need to know a venv is active. This is pure infrastructure.
- No command rewriting — We trust
PATHprecedence. Absolute paths like/usr/bin/pipare rare and not worth the fragility of interception. - No
spawnHook— Process-level env mutation coversbashtool,!commands,pi.exec(), and other extensions. - MS Store shim detection — On Windows, broken
python3shims (exit code 49) are automatically skipped during Python discovery. - Dead venv recovery — If the shared venv's underlying Python was removed or upgraded, it is detected and recreated on the next session start.
License
MIT
