Hi Martin,
> add some print statements to ./support/_mountzlib and try to find a way
> how to unset environment variable from Python on AIX.
The problem is that 'os.unsetenv()' does not exist on AIX (or at least
not in my Python installation on AIX). Therefore
del os.environ['_MEIPASS2']
does not delete the variable from the environment.
My workaround is to set the variable to the empty string only if the
function 'os.unsetenv()' does not exist. Also, I have to make the
bootloader robust so it will treat an empty string the same way as an
non-existing _MEIPASS2 variable.
Does that sound like a reasonable approach?
Below is my (untested) patch, so you can see, what I am doing.
/Martin
diff --git a/source/common/main.c b/source/common/main.c
--- a/source/common/main.c
+++ b/source/common/main.c
@@ -75,6 +75,22 @@
get_homepath(homepath, thisfile);
extractionpath = getenv( "_MEIPASS2" );
+
+ /* If the Python program we are about to run invokes another
PyInstaller
+ * one-file program as subprocess, this subprocess must not be
fooled into
+ * thinking that it is already unpacked. Therefore, PyInstaller
deletes
+ * the _MEIPASS2 variable from the environment in _mountzlib.py.
+ *
+ * However, on some platforms (e.g. AIX) the Python function
'os.unsetenv()'
+ * does not always exist. In these cases we cannot delete the
_MEIPASS2
+ * environment variable from Python but only set it to the empty
string.
+ * The code below takes into account that _MEIPASS2 may exist
while its
+ * value is only the empty string.
+ */
+ if (*extractionpath = 0) {
+ extractionpath = NULL;
+ }
+
VS("_MEIPASS2 is %s\n", (extractionpath ? extractionpath :
"NULL"));
if (init(status_list[SELF], homepath,
&thisfile[strlen(homepath)])) {
diff --git a/support/_mountzlib.py b/support/_mountzlib.py
--- a/support/_mountzlib.py
+++ b/support/_mountzlib.py
@@ -60,13 +60,21 @@
# But we need to preserve _MEIPASS2 value for cases where reseting it
# causes some issues (e.g. multiprocess module on Windows).
# set sys._MEIPASS
-if '_MEIPASS2' in os.environ:
- sys._MEIPASS = os.environ['_MEIPASS2']
+MEIPASS2name = '_MEIPASS2'
+if MEIPASS2name in os.environ:
+ sys._MEIPASS = os.environ[MEIPASS2name]
# Ensure sys._MEIPASS is absolute path.
sys._MEIPASS = os.path.normpath(sys._MEIPASS)
sys._MEIPASS = os.path.abspath(sys._MEIPASS)
# Delete _MEIPASS2 from environment.
- del os.environ['_MEIPASS2']
+ del os.environ[MEIPASS2name]
+
+ # On some platforms (e.g. AIX) 'os.unsetenv()' is not available
and then
+ # deleting the var from os.environ does not delete it from the
environment.
+ # In those cases we cannot delete the variable but only set it to
the
+ # empty string.
+ if not hasattr(os, 'unsetenv'):
+ os.putenv(MEIPASS2name, '')
--
You received this message because you are subscribed to the Google Groups
"PyInstaller" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyinstaller?hl=en.