bpo-35872 and bpo-35873: Clears __PYVENV_LAUNCHER__ variable (GH-11745)
After reading __PYVENV_LAUNCHER__ we now set sys._base_executable value for later use.
Make the same changes for macOS to avoid extra platform checks.
diff --git a/Lib/site.py b/Lib/site.py
index ffd132b..ad11463 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -457,7 +457,14 @@
env = os.environ
if sys.platform == 'darwin' and '__PYVENV_LAUNCHER__' in env:
- executable = os.environ['__PYVENV_LAUNCHER__']
+ executable = sys._base_executable = os.environ['__PYVENV_LAUNCHER__']
+ elif sys.platform == 'win32' and '__PYVENV_LAUNCHER__' in env:
+ executable = sys.executable
+ import _winapi
+ sys._base_executable = _winapi.GetModuleFileName(0)
+ # bpo-35873: Clear the environment variable to avoid it being
+ # inherited by child processes.
+ del os.environ['__PYVENV_LAUNCHER__']
else:
executable = sys.executable
exe_dir, _ = os.path.split(os.path.abspath(executable))