Skip to content

Commit a6a8524

Browse files
bpo-35811: Avoid propagating venv settings when launching via py.exe (GH-11677)
(cherry picked from commit adad9e6) Co-authored-by: Steve Dower <[email protected]>
1 parent 6a9c0fc commit a6a8524

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid propagating venv settings when launching via py.exe

PC/launcher.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,17 @@ process(int argc, wchar_t ** argv)
17071707
command = skip_me(GetCommandLineW());
17081708
debug(L"Called with command line: %ls\n", command);
17091709

1710+
#if !defined(VENV_REDIRECT)
1711+
/* bpo-35811: The __PYVENV_LAUNCHER__ variable is used to
1712+
* override sys.executable and locate the original prefix path.
1713+
* However, if it is silently inherited by a non-venv Python
1714+
* process, that process will believe it is running in the venv
1715+
* still. This is the only place where *we* can clear it (that is,
1716+
* when py.exe is being used to launch Python), so we do.
1717+
*/
1718+
SetEnvironmentVariableW(L"__PYVENV_LAUNCHER__", NULL);
1719+
#endif
1720+
17101721
#if defined(SCRIPT_WRAPPER)
17111722
/* The launcher is being used in "script wrapper" mode.
17121723
* There should therefore be a Python script named <exename>-script.py in

0 commit comments

Comments
 (0)