Ronald Oussoren <ronaldousso...@mac.com> added the comment:

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 Python.app 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue22490>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to