Skip to content

Replace pyvenv.cfg's home key with base-prefix and base-exec-prefix #127895

Open

Description

@FFY00

Feature or enhancement

Proposal:

The home key in pyvenv.cfg is used to specify the directory where the base Python executable is. During the Path Initialization, this directory, and consecutively its parents, is searched for stdlib landmarks to determine sys.base_prefix and sys.base_exec_prefix. Naturally, this isn't ideal, it would be better if pyvenv.cfg contained these values directly.

Proposed plan:

  • Update venv to start setting the base-prefix and base-exec-prefix keys in pyvenv.cfg when creating/updating environments
  • In getpath, use the base-prefix and base-exec-prefix keys to set the prefixes
  • Deprecate specifying home, in pyvenv.cfg

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Activity

  1. added
    type-featureA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    topic-venvRelated to the venv module
    on Dec 12, 2024
  2. FFY00 commented on Dec 12, 2024

    @FFY00
    MemberAuthor

    Optionally, we can also maybe add base-executable, to initialize sys._base_executable.

  3. pelson commented on Jan 9, 2025

    @pelson
    Contributor

    I also independently advocated for this yesterday in #106045 (comment). I then realised that these heuristics are also being used for non-venv based prefix determination, and now appreciate that when running a plain CPython interpreter, all you have is the executable path (plus a sysconfig full of paths for where Python was built) and heuristics are seemingly still necessary.

    If we could remove the need for the core interpreter heuristics (e.g. by only using the build config), then I think we should also remove the heuristics from venv exec/prefix determination.

    On the other hand, if we don't manage to remove the heuristics at the core, then I would advocate for removing home and replacing it with base-executable, since ultimately that is what is important from a venv path determination perspective.

    All of this sounds like it needs a change to PEP-405 though?

  4. charliermarsh commented on Jan 11, 2025

    @charliermarsh

    FWIW, I believe I agree with this, based on my experience computing home in uv.

  5. mayeut commented on Jan 12, 2025

    @mayeut
    Contributor

    Optionally, we can also maybe add base-executable

    I wonder if it wouldn't be required for venv launchers anyway (if not required, it would certainly simplify various paths computations in those launchers).
    If this gets exposed, it should be made public.

  6. brettcannon commented on May 31, 2025

    @brettcannon
    Member

    I'm not sure if @vsajip has an opinion on this. I'm personally fine with the proposal (including adding base-executable).

  7. vsajip commented on May 31, 2025

    @vsajip
    Member

    I have no problems with it either.

  8. pelson commented on Jun 2, 2025

    @pelson
    Contributor

    I believe there are two proposals on the table:

    • (Original proposal): setting the base-prefix and base-exec-prefix keys in pyvenv.cfg. Additionally setting base-executable. Deprecate home.
    • (My adapted proposal): setting base-executable, not setting base-exec-prefix and base-prefix and, as as argued above, use the same logic that is used for the normal startup sequence to determine them. Deprecate home.

    My proposal avoids the redundancy of setting both base-exec-prefix and base-executable, and does not seek to introduce the ability to control the prefix independently of the exec-prefix (which is not possible with PEP-405, but may be one of the motivations of the original proposal? ).

    Either approach is an improvement on the existing home mechanism IMO (since we no longer need to guess the executable so that we can proceed to guess the prefix and exec-prefix), and I'd be happy to take on the work, especially if there is somebody who would be willing to provide some mentorship (this would be my first CPython change which deprecates something specified in a PEP).

    I note that PEP-405 states:

    If a home key is found, this signifies that the Python binary belongs to a virtual environment, and the value of the home key is the directory containing the Python executable used to create this virtual environment.

    I think this would need to be changed according to the proposals above (since I don't think this would take precedence over base-executable, if found).

  9. brettcannon commented on Jun 9, 2025

    @brettcannon
    Member

    I believe there are two proposals on the table

    My comment was in regards to the proposal from @FFY00 . In the end, though, probably either is fine and it will be up to the core dev who does the work to choose what to go with. I'm here just trying to keep this moving so it can get closed out somehow.

    I note that PEP-405 states

    Non-active PEPs, once accepted, are historical documents, so it doesn't matter what it says at this point.

  10. zanieb commented on Aug 13, 2026

    @zanieb
    Contributor

    I think base-executable would be needed to solve #122033

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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-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