Repository navigation
Deprecate and eventually remove macOS-only PYTHONEXECUTABLE environ variable #91057
Description
Activity
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
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.
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.- marked PYTHONEXECUTABLE envvar incorrectly doc'd as mac-only and ignored by -E/-I #133525 as a duplicate of this issue
on May 18, 2026 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.PYTHONEXECUTABLEis indeed no longer Mac specific, it is mostly a synonym for__PYVENV_LAUNCHER__now; seegetpath.py:Lines 304 to 325 in 2f064fb
if ENV_PYTHONEXECUTABLE or ENV___PYVENV_LAUNCHER__: # If set, these variables imply that we should be using them as # sys.executable and when searching for venvs. However, we should # use the argv0 path for prefix calculation if os_name == 'darwin' and WITH_NEXT_FRAMEWORK: # In a framework build the binary in {sys.exec_prefix}/bin is # a stub executable that execs the real interpreter in an # embedded app bundle. That bundle is an implementation detail # and should not affect base_executable. base_executable = f"{dirname(library)}/bin/python{VERSION_MAJOR}.{VERSION_MINOR}" else: # Use the real executable as our base, or argv[0] otherwise # (on Windows, argv[0] is likely to be ENV___PYVENV_LAUNCHER__; on # other platforms, real_executable is likely to be empty) base_executable = real_executable or executable if not real_executable: real_executable = base_executable #real_executable_dir = dirname(real_executable) executable = ENV_PYTHONEXECUTABLE or ENV___PYVENV_LAUNCHER__ executable_dir = dirname(executable) This is the only location where either variable is actually read and used, outside of tests.
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:
bugs.python.org fields: