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
Deprecate and eventually remove macOS-only PYTHONEXECUTABLE environ variable #91057
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2022-03-02.17:45:33.785>labels= ['OS-mac', '3.11', 'docs']
title='Deprecate and eventually remove macOS-only PYTHONEXECUTABLE environ variable'updated_at=<Date2022-03-02.17:45:33.785>user='https://github.com/ned-deily'
The PYTHONEXECUTABLE is a holdover from old Python 2 days; AFAIK, it was specifically to support the Build Applet tool which could be used to build macOS app bundles in Python 2. The only place in current Py3 releases where it is used is in the standard library is in the launch of IDLE.app, a usage that should be able to be eliminated. Otherwise, there shouldn't be any need for it by third-parties. For 3.11, we could eliminate its use by IDLE.app and add a deprecation warning to the docs; not sure about an execution time warning?
I've found the PYTHONEXECUTABLE environment variable incredibly valuable for the particular case of relocatable virtual environments in read-only file systems using a wrapper script (not symlink) for the venv's bin/python. This case is common in the Bazel ecosystem, where as much as possible is created and determined at build time, and then copied over to a target system to actually run as-is.
In this case, what the PYTHONEXECUTABLE envvar essentially allows is allowing Python to find the underlying interpreter's home directory (which lets it find the interpreter's stdlib etc), while letting site.py's logic look at the venv's directory for e.g site-packages and sys.executable.
The net effect is you can copy a venv directory between systems without having to recreate pyvenv.cfg or the symlinks.
Also: PYTHONEEXECUTABLE is no-longer Mac specific. I'd have to go dig up issue/PR, but checking it only on Mac was intentionally dropped.
Looking into this a bit more, I would like to see the use case of relocatable virtual environments treated as a separate feature that is properly supported and documented rather than using a backdoor 'trick'. I could be misremembering but I think the fact that PYTHONEXECUTABLE is no longer macOS-specific is likely due to an oversight during the rewrite of getpath processing in Python 3.11 rather than an intended change. Most of the references to PYTHONEXECUTABLE in the cpython repo are still macOS-specific. And venvs are specifically documented as being not portable in the general case. I expect there are already other open issues requesting venv portability.
I could be misremembering but I think the fact that PYTHONEXECUTABLE is no longer macOS-specific is likely due to an oversight during the rewrite of getpath processing in Python 3.11 rather than an intended change.
PYTHONEXECUTABLE is indeed no longer Mac specific, it is mostly a synonym for __PYVENV_LAUNCHER__ now; see getpath.py:
Activity
ned-deily commentedon Mar 2, 2022
The PYTHONEXECUTABLE is a holdover from old Python 2 days; AFAIK, it was specifically to support the Build Applet tool which could be used to build macOS app bundles in Python 2. The only place in current Py3 releases where it is used is in the standard library is in the launch of IDLE.app, a usage that should be able to be eliminated. Otherwise, there shouldn't be any need for it by third-parties. For 3.11, we could eliminate its use by IDLE.app and add a deprecation warning to the docs; not sure about an execution time warning?
https://docs.python.org/3/using/cmdline.html#envvar-PYTHONEXECUTABLE
rickeylev commentedon May 6, 2025
Hi,
I've found the PYTHONEXECUTABLE environment variable incredibly valuable for the particular case of relocatable virtual environments in read-only file systems using a wrapper script (not symlink) for the venv's
bin/python. This case is common in the Bazel ecosystem, where as much as possible is created and determined at build time, and then copied over to a target system to actually run as-is.In this case, what the PYTHONEXECUTABLE envvar essentially allows is allowing Python to find the underlying interpreter's home directory (which lets it find the interpreter's stdlib etc), while letting site.py's logic look at the venv's directory for e.g site-packages and sys.executable.
The net effect is you can copy a venv directory between systems without having to recreate pyvenv.cfg or the symlinks.
Also: PYTHONEEXECUTABLE is no-longer Mac specific. I'd have to go dig up issue/PR, but checking it only on Mac was intentionally dropped.
ned-deily commentedon May 18, 2026
Looking into this a bit more, I would like to see the use case of relocatable virtual environments treated as a separate feature that is properly supported and documented rather than using a backdoor 'trick'. I could be misremembering but I think the fact that
PYTHONEXECUTABLEis no longer macOS-specific is likely due to an oversight during the rewrite ofgetpathprocessing in Python 3.11 rather than an intended change. Most of the references toPYTHONEXECUTABLEin the cpython repo are still macOS-specific. Andvenvs are specifically documented as being not portable in the general case. I expect there are already other open issues requestingvenvportability.mjpieters commentedon Jun 5, 2026
PYTHONEXECUTABLEis indeed no longer Mac specific, it is mostly a synonym for__PYVENV_LAUNCHER__now; seegetpath.py:cpython/Modules/getpath.py
Lines 304 to 325 in 2f064fb
This is the only location where either variable is actually read and used, outside of tests.