This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ronaldoussoren
Recipients Anders.Hovmöller, gvanrossum, jaraco, ned.deily, ronaldoussoren, tdsmith, vinay.sajip
Date 2018-09-23.10:59:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The pull request is wrong, the use of __PYVENV_LAUNCHER__ in pythonw.c is correct and should not be removed. Where the current code goes wrong is that it doesn't clear the environment as soon as possible.

This patch should basically do the trick (but requires testing and probably adjustments to some other code):

diff --git a/Modules/main.c b/Modules/main.c
index 3a6cf31fc8..c673d06c56 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -1360,6 +1360,8 @@ config_init_program_name(_PyCoreConfig *config)
                                          "variable", (Py_ssize_t)len);
             config->program_name = program_name;
+           unsetenv("__PYVENV_LAUNCHER__");
             return _Py_INIT_OK();

Some background information on why and environment variable is used on macOS when using a framework install:  To use system GUI frameworks on macOS the executable should be part of an application bundle (".app"), otherwise a number of APIs just don't work (which would affect the use of for example Tkinter in command-line scripts).  To work around this platform limitation a framework install of Python has the actual interpreter in a bundle stored in the framework, and "{sys.prefix}/bin/python" is a small stub executable that launches the real interpreter. 

The environment variable is used to pass the path to the stub executable to the real interpreter, to enable it to behave correctly (look at venv configuration files, have sys.executable be correct, ...). 

That said, looking at the code it might be possible to do away with the environment variable after call because the code in pythonw.c suggests the the environment variable is only necessary for OSX 10.5 or earlier.

I'm working on an alternative pull request that implements the patch I included inline in this message, with some additional documentation.
Date User Action Args
2018-09-23 10:59:46ronaldoussorensetrecipients: + ronaldoussoren, gvanrossum, vinay.sajip, jaraco, ned.deily, Anders.Hovmöller, tdsmith
2018-09-23 10:59:46ronaldoussorensetmessageid: <>
2018-09-23 10:59:46ronaldoussorenlinkissue22490 messages
2018-09-23 10:59:45ronaldoussorencreate