From 816163ecfffc01e34a271243408780bc77263cab Mon Sep 17 00:00:00 2001 From: Armando Montanez Date: Fri, 19 Jan 2024 17:10:26 -0800 Subject: [PATCH] fix: fix launching Python 3.11 from <3.8 on macOS On macOS, some older versions of Python leak __PYVENV_LAUNCHER__ into the interpreter's environment variables. Starting with Python 3.11, this causes problems with Python being able to start correctly when launched from the Python bootstrap template. This change introduces a workaround to prevent the problematic environment variable from leaking into launched subprocesses. I've verified this problem exists with the version of Python 3.7 included with Xcode, and there are reports of it also being an issue with the Python 3.8 included with Xcode. Later versions of Python have fixed this. Context: - https://issues.pigweed.dev/310293060 - https://github.com/xonsh/xonsh/issues/3576#issuecomment-629013991 - https://github.com/pypa/virtualenv/issues/1458 --- python/private/python_bootstrap_template.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/private/python_bootstrap_template.txt b/python/private/python_bootstrap_template.txt index 92dd6b82f..59313cfec 100644 --- a/python/private/python_bootstrap_template.txt +++ b/python/private/python_bootstrap_template.txt @@ -528,6 +528,13 @@ def Main(): else: cov_tool = None + # Some older Python versions on macOS (namely Python 3.7) may unintentionally + # leave this environment variable set after starting the interpreter, which + # causes problems with Python subprocesses correctly locating sys.executable, + # which subsequently causes failure to launch on Python 3.11 and later. + if '__PYVENV_LAUNCHER__' in os.environ: + del os.environ['__PYVENV_LAUNCHER__'] + new_env.update((key, val) for key, val in os.environ.items() if key not in new_env) workspace = None