Skip to content

Commit

Permalink
fix: fix launching Python 3.11 from <3.8 on macOS
Browse files Browse the repository at this point in the history
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
- xonsh/xonsh#3576 (comment)
- pypa/virtualenv#1458
  • Loading branch information
armandomontanez committed Jan 20, 2024
1 parent 711186f commit 816163e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/private/python_bootstrap_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 816163e

Please sign in to comment.