Skip to content

Warn when running in a virtual environment that was created for a different minor Python version #127727

Closed

Description

@FFY00

Feature or enhancement

Proposal:

Environment paths change between minor Python version. When a virtual environment's base Python installation gets updated, the site-packages directories, for eg, will be different, meaning Python won't be able to access any previously installed packages (nor would we want to, as they may be incompatible).

On these situations, we could issue a warning suggesting the user to run python -m venv --upgrade.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. added
    type-featureA feature request or enhancement
    topic-venvRelated to the venv module
    on Dec 7, 2024
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Dec 7, 2024
  3. user21t commented on Dec 11, 2024

    @user21t

    Hello. As far as I know, the only way to update the virtual environment's base Python installation is to create a new environment with updated Python, using venv. Then, after installing dependencies required by our project via pip, we migrate project files from the old environment to the new one. That may include pyvenv.cfg which still has information about old environment's Python version.
    But before brainstorming, I would like to know one thing: how should the new environment's Python interpreter recognize that it is working with a project from the old environment?

  4. FFY00 commented on Dec 12, 2024

    @FFY00
    MemberAuthor

    As far as I know, the only way to update the virtual environment's base Python installation is to create a new environment with updated Python, using venv.

    You can do this in the same prefix via python -m venv --upgrade.

    But before brainstorming, I would like to know one thing: how should the new environment's Python interpreter recognize that it is working with a project from the old environment?

    By looking at the version (used by venv) and version_info (used by virtualenv) keys in pyvenv.cfg.

  5. user21t commented on Dec 12, 2024

    @user21t

    @FFY00 Thank you for explanation.

  6. added a commit that references this issue on Jun 22, 2026
  7. added a commit that references this issue on Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-venvRelated to the venv moduletype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions