Skip to content

venv manager

Quadstronaut edited this page Jun 11, 2026 · 2 revisions

venv_manager — CLI Reference

venv_manager.py is a small command-line utility for creating, listing, and deleting Python virtual environments in the current working directory. It wraps the stdlib venv module and shutil.rmtree behind a consistent subcommand interface.

No installation required — it is a single-file script with stdlib-only dependencies.

Platform notes

The script is Unix-oriented (macOS/Linux). It has no Windows-specific handling:

  • Environment detection (list): checks only for bin/activate. Windows venvs use Scripts\activate.bat — those will not be detected.
  • create command: always calls python3 -m venv. On Windows, python3 may not exist in PATH; creation will fail with Error: 'python3' command not found.
  • Activation instructions: always prints the Unix form source <env>/bin/activate.

Running on Windows without modification will produce incorrect results or errors for list and create.

Usage

python venv_manager.py <command> [arguments]

Run without arguments to print the help message.

Commands

list

Lists all virtual environments found in the current working directory.

python venv_manager.py list

A directory is considered a virtual environment if it contains bin/activate. Subdirectories that fail this check are ignored. Windows venvs (Scripts\activate.bat) are not detected.

Output example:

Listing virtual environments in the current directory:
✅ myenv
✅ testenv

To activate an environment, use: 'source <env_name>/bin/activate'

If no environments are found, prints: No virtual environments found.

create <name>

Creates a new virtual environment with the given name in the current directory.

python venv_manager.py create <name>
Argument Type Description
name string Directory name for the new virtual environment

Behavior:

  • Calls python3 -m venv <name> (Unix only; python3 is hardcoded).
  • Prints the activation command for the current OS on success.
  • Reports a clear error if python3 is not found in PATH.
  • Reports a clear error (including stderr from the venv command) on failure.

Error cases:

  • Python not found in PATH → Error: 'python3' command not found.
  • Directory already exists with the same name → reported via subprocess.CalledProcessError

delete <name>

Deletes an existing virtual environment by removing its directory tree.

python venv_manager.py delete <name>
Argument Type Description
name string Name of the virtual environment to delete

Behavior:

  • Checks that <name> exists before proceeding; exits with an error message if not.
  • Prompts for confirmation before deleting: Are you sure you want to delete '<name>'? (y/n).
    • y → deletes the directory with shutil.rmtree.
    • Any other input → prints Deletion cancelled. and exits without deleting.

Note: This is an interactive script — delete requires stdin input. It cannot be run non-interactively without modification.

Examples

# Create a virtual environment named 'myproject'
python venv_manager.py create myproject

# List all virtual environments in the current directory
python venv_manager.py list

# Delete a virtual environment (will prompt for confirmation)
python venv_manager.py delete myproject

Known limitations

  • list detects environments only in the current working directory (depth 1). Nested environments are not found.
  • delete removes any directory named <name>, not just directories that pass the venv detection check. Passing the wrong name can delete unrelated directories.
  • No activate subcommand — activation modifies the shell environment and cannot be done by a subprocess. Use the printed activation command directly in your shell.

Clone this wiki locally