Skip to content

[Feature Request] Track and report usage of virtualenvs across project directories #513

@aksajja

Description

@aksajja

Description

pyenv-virtualenv keeps track of all virtual environments created using pyenv virtualenv, but does not track where those environments are used (i.e., which directories contain .python-version files referencing them).

This feature would improve environment management by logging usage context and allowing users to query where virtualenvs are active.

Problem

  • No way to map virtualenvs to the directories that use them
  • Makes it hard to clean up, audit, or understand which projects rely on which environments
  • Users have to manually grep for .python-version files to infer usage

Proposed Feature

Introduce optional usage tracking for virtualenvs:

  • When a virtualenv is activated (via pyenv activate, or a .python-version triggers it), log an entry with:
    • Timestamp
    • Virtualenv name
    • Path to the directory where it was used

Provide a new CLI command:

  • pyenv virtualenv usage — List all usage across virtualenvs
  • pyenv virtualenv usage <env-name> — Show where a specific env is used

Logging should be opt-in via an environment variable or config, such as:

export PYENV_VIRTUALENV_LOG_USAGE=1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions