You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
linux python3.7 can not found '/tmp/_MEIZLLDaA/libpython3.7m.so‘ #6831
Did you also try this on another platform? Does it work there? :no
Description of the issue
1、I have a python file HelloServer.py
2、pyinstaller -F HelloServer.py --distpath .
3、generate HelloServer succ
Every time I modify the code HelloServer.py and repackage HelloServer 。
The strange is
sometimes HelloServer run succ with out any error;
sometimes HelloServer run fail with error like this:
[21318] Error loading Python lib '/tmp/_MEIZLLDaA/libpython3.7m.so': dlopen: /tmp/MEIZLLDaA/libpython3.7m.so: cannot open shared object file: No such file or directory
"/tmp/_MEIZLLDaA/libpython3.7m.so" is not exsit in my system , and the right position is "~/miniconda3/envs/py37/lib/libpython3.7m.so"
/tmp/_MEIXXXXXX is a temporary directory where one-file (-F) build unpacks its content each time it is run. The last six characters in name are randomly generated, so they are different each time; and the temporary directory is cleaned up once the program finishes, so you will see it exist only while the program is running.
Therefore, /tmp/_MEIZLLDaA/libpython3.7m.so is a correct path, because PyInstaller-frozen program should contain a copy of python shared library. You can verify that the library is collected by using pyi-archive_viewer command-line utility to list the contents of the programs' embedded archive - you should see the libpython3.7m.so among the listed contents.
So if the (same) program runs sometimes but sometimes gives the error (on the same machine), then there might be a problem with unpacking to the temporary directory (insufficient space?), or with some other program/service removing the temporary files (although that's quite a race for removal to happen right at the early stages of program run). Either way, you should probably investigate what is going on with the temporary directory.
/tmp/_MEIXXXXXX is a temporary directory where one-file (-F) build unpacks its content each time it is run. The last six characters in name are randomly generated, so they are different each time; and the temporary directory is cleaned up once the program finishes, so you will see it exist only while the program is running.
Therefore, /tmp/_MEIZLLDaA/libpython3.7m.so is a correct path, because PyInstaller-frozen program should contain a copy of python shared library. You can verify that the library is collected by using pyi-archive_viewer command-line utility to list the contents of the programs' embedded archive - you should see the libpython3.7m.so among the listed contents.
So if the (same) program runs sometimes but sometimes gives the error (on the same machine), then there might be a problem with unpacking to the temporary directory (insufficient space?), or with some other program/service removing the temporary files (although that's quite a race for removal to happen right at the early stages of program run). Either way, you should probably investigate what is going on with the temporary directory.
Thank you for your answer~
I have checked the space,space is enough.
when i run 'pyinstaller -F HelloServer.py --distpath .' to generate HelloServer。
If first time HelloServer run succ, then follow-up run is always succ
and i did not change any code,but only run 'pyinstaller -F HelloServer.py --distpath .' to generate HelloServer again.
If first time HelloServer run fail, then follow-up run is always fail
so the variable is only i run the repackage command ~
In that case, when you get a build that fails with the error, can you list its contents using pyi-archive_viewer, and compare it to the contents of a good build?
use pyi-archive_viewer to compare each other ,
pyi-archive_viewer succ/HelloServer1 pyi-archive_viewer succ/HelloServer2...
pyi-archive_viewer fail/HelloServer1 pyi-archive_viewer fail/HelloServer2...
PYZ-00.pyz being different should have no impact on the libpython3.7m.so error; but you can try to ensure that builds are reproducible by settings PYTHONHASHSEED, as described here. So libpython3.7m.so is collected in all cases, and has the same size?
Just to be sure, can you use pyi-archive_viewer to extract libpython3.7m.so from both a successful and failing program, and compare them (e.g., via some checksum value)?
Does it make any difference if you relocate the temporary directory? For example, create a test-tmp in user's home directory (mkdir ~/test-tmp) and then run the failing program as TMPDIR=~/test-tmp ./fail/HelloServer1?
PYZ-00.pyz being different should have no impact on the libpython3.7m.so error; but you can try to ensure that builds are reproducible by settings PYTHONHASHSEED, as described here. So libpython3.7m.so is collected in all cases, and has the same size?
Just to be sure, can you use pyi-archive_viewer to extract libpython3.7m.so from both a successful and failing program, and compare them (e.g., via some checksum value)?
Does it make any difference if you relocate the temporary directory? For example, create a test-tmp in user's home directory (mkdir ~/test-tmp) and then run the failing program as TMPDIR=~/test-tmp ./fail/HelloServer1?
By your advice :
I set the PYTHONHASHSEED to "Creating a Reproducible Build " , and I use md5sum(HelloServer) to confirm the effectiveness
Hmmm... I did some testing in a VM with CentOS 7.9 and anaconda, and it seems that sometimes, we pick up libpython3.7m.so.1.0 as the python shared library, and sometimes we pick up libpython3.7m.so (which should be a symlink to the former in the original conda's lib directory). In my case, both combinations seem to work, though.
Can you check if this is the difference? Are successful builds using libpython3.7m.so.1.0 as the library name, and failing ones libpython3.7m.so?
If you re-build the program again with PYTHONHASHSEED=1 and PYTHONHASHSEED=4, check the build log for messages like these:
[...]
3504 INFO: Looking for eggs
3504 INFO: Python library not in binary dependencies. Doing additional searching...
3526 INFO: Using Python library [...]/lib/libpython3.7m.so
[...]
Then, check the build/<name>/PKG-00.toc and find the entry for libpython*. Finally, check the generated executable with pyi-archive-viewer to see what the name of collected libpython* is there. Do the names match? And lastly, do they match the name of library reported in the error when the failing build fails to run?
On the other hand, does the same problem occur if you try to build a different program? For example, a simple "Hello world" script? If it does, can you create a failing build of such a simple script and upload it somewhere so I can take a look at it?
And i use a simple program only print "Hello Word!" to reproduce the problem (set PYTHONHASHSEED from 1 to 20), it is always run succ 。
HelloWorld.py
import os
print ("workdir :" , os.getcwd() )
print ("HelloWorld!")
So it can be confirmed that the case of responsible search led to this problem.
My program is a little complicated. It refers to a so file compiled by C + + based on pybind11 (https://github.com/pybind/pybind11)
And i have mailed the build diffrence to you (rok.mandeljc@gmail.com)
This name is stored at the end of generated PKG file (which is added to the EXE), but it is not visible to the pyi-archive-viewer, nor is it visible in the build log. And, according to my earlier tests, we sometimes pick up libpython3.7m.so.1.0 and sometimes libpython3.7m.so.
However, we ensure that the python library is actually collected in another part of the code - earlier, in Analysis:
As long as python shared library has not been already collected, we use the same bindepend.get_python_library_path() function, whose output within the same program run seems to be stable (i.e., always gives back the same name). So the name of collected shared library and expected name of the shared library match, and everything works.
But a pybind11-based extension is probably also linked against python shared library, which always causes libpython3.7m.so.1.0 to be collected. But the bindepend.get_python_library_path() call is not aware of that, which (on some runs) results in a mismatch between the actual collected library name and the expected one, resulting in the error.
The cleanest way to fix this would probably be to propagate the determined shared library name from Analysis to other objects (i..e, EXE and PKG). But that requires modification of the templates, which means that it won't work for already-generated specs (though we could make it so that nothing changes for existing specs with default value of additional parameters being None).
We could also have bindepend.get_python_library_path() resolve symlinks, so instead of libpython3.X.so it returns libpython3.X.so.1.0. This should help in cases when other binaries are also linked against the python shared library, because the linker should resolve against versioned .so's (to enforce ABI compatibility). It would not help if someone also (manually) collected libpython3.X.so, though.
I thought this would have implications for linux in general, but it turns out it affects only Anaconda, because we search library directories there, whereas regular linux codepath uses linker-based search, which already resolves libpython3.x.so into versioned libpython3.x.so.1.0 (or whatever name the unversioned name points to; e.g., libpython3.8.so.rh-python38-1.0 under RH SCL python):
Activity
rokm commentedon May 18, 2022
/tmp/_MEIXXXXXXis a temporary directory where one-file (-F) build unpacks its content each time it is run. The last six characters in name are randomly generated, so they are different each time; and the temporary directory is cleaned up once the program finishes, so you will see it exist only while the program is running.Therefore,
/tmp/_MEIZLLDaA/libpython3.7m.sois a correct path, because PyInstaller-frozen program should contain a copy of python shared library. You can verify that the library is collected by usingpyi-archive_viewercommand-line utility to list the contents of the programs' embedded archive - you should see thelibpython3.7m.soamong the listed contents.So if the (same) program runs sometimes but sometimes gives the error (on the same machine), then there might be a problem with unpacking to the temporary directory (insufficient space?), or with some other program/service removing the temporary files (although that's quite a race for removal to happen right at the early stages of program run). Either way, you should probably investigate what is going on with the temporary directory.
shenyuhit commentedon May 18, 2022
Thank you for your answer~
I have checked the space,space is enough.
when i run 'pyinstaller -F HelloServer.py --distpath .' to generate HelloServer。
If first time HelloServer run succ, then follow-up run is always succ
and i did not change any code,but only run 'pyinstaller -F HelloServer.py --distpath .' to generate HelloServer again.
If first time HelloServer run fail, then follow-up run is always fail
so the variable is only i run the repackage command ~
rokm commentedon May 18, 2022
In that case, when you get a build that fails with the error, can you list its contents using
pyi-archive_viewer, and compare it to the contents of a good build?shenyuhit commentedon May 19, 2022
I package HelloServer for many times and get 4 succ executable , 4 fail executable ( the same machine and with out change code ).
use pyi-archive_viewer to compare each other ,
pyi-archive_viewer succ/HelloServer1 pyi-archive_viewer succ/HelloServer2...
pyi-archive_viewer fail/HelloServer1 pyi-archive_viewer fail/HelloServer2...
the difference at PYZ-00.pyz :
But there seems to be no obvious difference , only the package size ..
And
I copy the succ executable to other machine ,it run succ;
I copy the fail executable to other machine ,it run fail;
rokm commentedon May 19, 2022
PYZ-00.pyzbeing different should have no impact on thelibpython3.7m.soerror; but you can try to ensure that builds are reproducible by settingsPYTHONHASHSEED, as described here. Solibpython3.7m.sois collected in all cases, and has the same size?Just to be sure, can you use
pyi-archive_viewerto extractlibpython3.7m.sofrom both a successful and failing program, and compare them (e.g., via some checksum value)?Does it make any difference if you relocate the temporary directory? For example, create a
test-tmpin user's home directory (mkdir ~/test-tmp) and then run the failing program asTMPDIR=~/test-tmp ./fail/HelloServer1?shenyuhit commentedon May 22, 2022
By your advice :
I set the PYTHONHASHSEED to "Creating a Reproducible Build " , and I use md5sum(HelloServer) to confirm the effectiveness
As shown above ,when i set PYTHONHASHSEED=4 to genarate the programme ,it is always run failure
I use pyi-archive_viewer to extract libpython3.7m.so from both a successful and failing program, they are the same (use md5 to confire).
"For example, create a test-tmp in user's home directory (mkdir
/test-tmp) and then run the failing program as TMPDIR=/test-tmp ./fail/HelloServer1"Any other suggestions ?
rokm commentedon May 22, 2022
Hmmm... I did some testing in a VM with CentOS 7.9 and anaconda, and it seems that sometimes, we pick up
libpython3.7m.so.1.0as the python shared library, and sometimes we pick uplibpython3.7m.so(which should be a symlink to the former in the original conda's lib directory). In my case, both combinations seem to work, though.Can you check if this is the difference? Are successful builds using
libpython3.7m.so.1.0as the library name, and failing oneslibpython3.7m.so?If you re-build the program again with PYTHONHASHSEED=1 and PYTHONHASHSEED=4, check the build log for messages like these:
Then, check the
build/<name>/PKG-00.tocand find the entry forlibpython*. Finally, check the generated executable withpyi-archive-viewerto see what the name of collectedlibpython*is there. Do the names match? And lastly, do they match the name of library reported in the error when the failing build fails to run?On the other hand, does the same problem occur if you try to build a different program? For example, a simple "Hello world" script? If it does, can you create a failing build of such a simple script and upload it somewhere so I can take a look at it?
shenyuhit commentedon May 23, 2022
I've compared the building process before ,i compared each build files , it seems no obvious differance
/home/upc/miniconda3/envs/py37/lib
lrwxrwxrwx. 1 upc upc 20 10月 26 2021 libpython3.7m.so -> libpython3.7m.so.1.0
-rwxrwxr-x. 2 upc upc 3808528 7月 27 2021 libpython3.7m.so.1.0
succ build:
...
3080 INFO: Using Python library /home/upc/miniconda3/envs/py37/lib/libpython3.7m.so.1.0
...
fail build:
...
3063 INFO: Using Python library /home/upc/miniconda3/envs/py37/lib/libpython3.7m.so.1.0
...
And I even deleted the symbol link , then copy the libpython3.7m.so.1.0 to libpython3.7m.so, it also has no effect
And i use a simple program only print "Hello Word!" to reproduce the problem (set PYTHONHASHSEED from 1 to 20), it is always run succ 。
HelloWorld.py
So it can be confirmed that the case of responsible search led to this problem.
My program is a little complicated. It refers to a so file compiled by C + + based on pybind11 (https://github.com/pybind/pybind11)
And i have mailed the build diffrence to you (rok.mandeljc@gmail.com)
rokm commentedon May 23, 2022
Aha, that's the missing piece of the puzzle. :)
What's going on is, the python shared library name that bootloader tries to load is determined here:
pyinstaller/PyInstaller/building/api.py
Lines 290 to 291 in dc09333
This name is stored at the end of generated
PKGfile (which is added to theEXE), but it is not visible to thepyi-archive-viewer, nor is it visible in the build log. And, according to my earlier tests, we sometimes pick uplibpython3.7m.so.1.0and sometimeslibpython3.7m.so.However, we ensure that the python library is actually collected in another part of the code - earlier, in
Analysis:pyinstaller/PyInstaller/building/build_main.py
Lines 643 to 661 in dc09333
As long as python shared library has not been already collected, we use the same
bindepend.get_python_library_path()function, whose output within the same program run seems to be stable (i.e., always gives back the same name). So the name of collected shared library and expected name of the shared library match, and everything works.But a pybind11-based extension is probably also linked against python shared library, which always causes
libpython3.7m.so.1.0to be collected. But thebindepend.get_python_library_path()call is not aware of that, which (on some runs) results in a mismatch between the actual collected library name and the expected one, resulting in the error.The cleanest way to fix this would probably be to propagate the determined shared library name from
Analysisto other objects (i..e,EXEandPKG). But that requires modification of the templates, which means that it won't work for already-generated specs (though we could make it so that nothing changes for existing specs with default value of additional parameters beingNone).We could also have
bindepend.get_python_library_path()resolve symlinks, so instead oflibpython3.X.soit returnslibpython3.X.so.1.0. This should help in cases when other binaries are also linked against the python shared library, because the linker should resolve against versioned .so's (to enforce ABI compatibility). It would not help if someone also (manually) collectedlibpython3.X.so, though.And perhaps we should also be dropping the un-versioned .so patterns fromEDIT: we shouldn't, because that will break RH SCL python.compat.PYDYLIB_NAMES, as those should be symlinks to versioned .so's anyway.rokm commentedon May 23, 2022
I thought this would have implications for linux in general, but it turns out it affects only Anaconda, because we search library directories there, whereas regular linux codepath uses linker-based search, which already resolves
libpython3.x.sointo versionedlibpython3.x.so.1.0(or whatever name the unversioned name points to; e.g.,libpython3.8.so.rh-python38-1.0under RH SCL python):pyinstaller/PyInstaller/depend/bindepend.py
Lines 890 to 900 in dc09333
Which I suppose kind of explains why we haven't seen this reported before.