You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Replace pyvenv.cfg's home key with base-prefix and base-exec-prefix #127895
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
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?
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.
(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).
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).
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.
Activity
FFY00 commentedon Dec 12, 2024
Optionally, we can also maybe add
base-executable, to initializesys._base_executable.pelson commentedon Jan 9, 2025
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
homeand replacing it withbase-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?
charliermarsh commentedon Jan 11, 2025
FWIW, I believe I agree with this, based on my experience computing
homein uv.mayeut commentedon Jan 12, 2025
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.
brettcannon commentedon May 31, 2025
I'm not sure if @vsajip has an opinion on this. I'm personally fine with the proposal (including adding
base-executable).vsajip commentedon May 31, 2025
I have no problems with it either.
pelson commentedon Jun 2, 2025
I believe there are two proposals on the table:
base-prefixandbase-exec-prefixkeys in pyvenv.cfg. Additionally settingbase-executable. Deprecatehome.base-executable, not settingbase-exec-prefixandbase-prefixand, as as argued above, use the same logic that is used for the normal startup sequence to determine them. Deprecatehome.My proposal avoids the redundancy of setting both
base-exec-prefixandbase-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
homemechanism IMO (since we no longer need to guess theexecutableso that we can proceed to guess theprefixandexec-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:
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).brettcannon commentedon Jun 9, 2025
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.
Non-active PEPs, once accepted, are historical documents, so it doesn't matter what it says at this point.
zanieb commentedon Aug 13, 2026
I think
base-executablewould be needed to solve #122033