Wrapping python3 -m venv for interactive workflows¶
A shell wrapper for Python's built-in venv module. Works in Bash and Zsh.
Python’s standard library provides python3 -m venv <venvname> for creating isolated environments. Over time, repeated interactive use tends to surface small points of repetition in how environments are created, located, activated, and removed. These are characteristics of usage rather than limitations of the tool itself.
Other tools in the ecosystem, such as Virtualenvwrapper, Poetry, and PDM, operate over a wider surface area, covering hook systems, dependency resolution, lock files, and project scaffolding.
In some cases, the scope remains narrower: reducing repetition in the environment lifecycle while staying within behavior already provided by venv.
Approach¶
The approach follows a single-directory layout and a setvenv-style activation command, implemented as shell functions without external dependencies.
The default storage location is ~/.virtualenvs/ and can be overridden via the VENV_HOME environment variable. Two completion functions are registered conditionally based on $BASH_VERSION or $ZSH_VERSION. Shell compatibility is handled at load time; the same file works in both Bash and Zsh.
The Python interpreter path is fixed at environment creation time. Switching the global Python version afterward doesn't affect existing environments.
Six functions are present:
mkvenv — create an environment and display Python version information
setvenv — activate an environment with tab completion
rmvenv — remove an environment with confirmation and auto-deactivation
lsvenv — list environments
whichvenv — show the active environment and Python version
pipclean — remove installed packages from the active environment
Scope¶
The script is limited to environment creation and lifecycle management.
It does not manage Python versions, resolve dependencies, generate lock files, auto-activate environments on directory change, or maintain project-to-environment mappings. These concerns are typically handled by other tools or conventions.
Design constraints¶
- No external dependencies beyond Python 3.3+ stdlib
- POSIX-compatible patterns (works in Bash and Zsh)
- Single-file distribution
- No implicit behavior
- Explicit confirmations for anything destructive