New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SHA1_init missing when using PyInstaller on OSX #5583
Comments
Can you please fill out the issue template. |
ok, it has been changed |
Can you try using from PyInstaller.utils.hooks import collect_dynamic_libs at the top and change
That at least ensures the right libraries are collected. |
Uf, this is a nasty subtle bug... There is a The loading is done via In both cases, the library is loaded by calling utility function with fully-qualified name, e.g., The extension suffices that are tested come from
This means than unfrozen version first tries to load
which fails as it does not exist. Then it tries
which succeeds. In frozen version, however, the first call with In pyinstaller/PyInstaller/loader/pyiboot01_bootstrap.py Lines 126 to 131 in 93285ec
called from pyinstaller/PyInstaller/loader/pyiboot01_bootstrap.py Lines 140 to 146 in 93285ec
The same thing happens with pyinstaller/PyInstaller/loader/pyiboot01_bootstrap.py Lines 193 to 199 in 93285ec
So long story short, we find a library that should not be found. (Although on the other hand, I understand why also checking _MEIPASS might be needed in other scenarios). |
@Robby0318, since your log indicates that you're using For example, try changing: def _frozen_name(name):
if name:
[...] to def _frozen_name(name):
if name and not os.path.isabs(name):
[...] and rebuild your application. (Although whether this will work depends a lot on behavior of other packages that you're using...) |
…ion libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly into _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resultingin inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (pyinstaller#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix.
On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly into _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as pyinstaller#5583.
…ion libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly in the _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resulting in inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (pyinstaller#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix.
On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly in the _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as in pyinstaller#5583.
…ion libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly in the _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resulting in inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (pyinstaller#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix.
On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly in the _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as in pyinstaller#5583.
…ion libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly in the _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resulting in inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (pyinstaller#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix.
On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly in the _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as in pyinstaller#5583.
…ion libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly in the _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resulting in inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (pyinstaller#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix.
On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly in the _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as in pyinstaller#5583.
…ion libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly in the _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resulting in inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (pyinstaller#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix.
On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly in the _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as in pyinstaller#5583.
…ion libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly in the _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resulting in inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (pyinstaller#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix.
On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly in the _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as in pyinstaller#5583.
…ion libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly in the _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resulting in inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (pyinstaller#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix.
On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly in the _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as in pyinstaller#5583.
…ion libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly in the _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resulting in inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (pyinstaller#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix.
On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly in the _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as in pyinstaller#5583.
I can confirm that my issue (pyinstaller/pyinstaller-hooks-contrib#109) was fixed by #5604. Thanks, @rokm! |
…5604) * tests: add test for ctypes.CDLL incorrectly picking up builtin extension libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly in the _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resulting in inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix. * building: collect built-in extensions into lib-dynload sub-directory On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly in the _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as in #5583. * bootloader: add _MEIPASS/lib-dynload to the initial sys.path * bootloader: ensure pypath and pypath_w buffers are of same size Having pypath with greater size than pypath_w invites potential trouble when path to executable is long enough that length of pypath string exceeds PATH_MAX. And it makes little sense for the two buffers to be of differently sized, anyway. * rebuild bootloaders Co-authored-by: Legorooj <legorooj@protonmail.com>
Now `python setup.py wheel_darwin_64bit` will generate a wheel whose platform (architecture and macOS deployment target) matches those of the bootloaders currently present in `PyInstaller/bootloader/Darwin-64bit`. An unfortunate, but minor, side-effect of this change is that PyInstaller itself must be installed to run `setup.py wheel_darwin_64bit`. As this command isn't needed to install PyInstaller, we avoid any need for bootstrap-installing.
…5583) Doing so enables the sdist to serve as a fallback if pip is too old to recognise the universal2 tagged wheel.
Now `python setup.py wheel_darwin_64bit` will generate a wheel whose platform (architecture and macOS deployment target) matches those of the bootloaders currently present in `PyInstaller/bootloader/Darwin-64bit`. An unfortunate, but minor, side-effect of this change is that PyInstaller itself must be installed to run `setup.py wheel_darwin_64bit`. As this command isn't needed to install PyInstaller, we avoid any need for bootstrap-installing.
…5583) Doing so enables the sdist to serve as a fallback if pip is too old to recognise the universal2 tagged wheel.
Now `python setup.py wheel_darwin_64bit` will generate a wheel whose platform (architecture and macOS deployment target) matches those of the bootloaders currently present in `PyInstaller/bootloader/Darwin-64bit`. An unfortunate, but minor, side-effect of this change is that PyInstaller itself must be installed to run `setup.py wheel_darwin_64bit`. As this command isn't needed to install PyInstaller, we avoid any need for bootstrap-installing.
Doing so enables the sdist to serve as a fallback if pip is too old to recognise the universal2 tagged wheel.
Description of the issue
There is no problem running the source code directly with python3 under OSX 11.1
When running the executable generated by PyInstaller, I get the following error message.
After testing, it is found that the
sha1_init
symbol is in the source codeCryptodome/Hash/_SHA1.abi3.so
library, and the_sha1.cpython-39m-darwin.so
generated by Pyinstaller does not have thesha1_init
symbol.Context information (for bug reports)
The text was updated successfully, but these errors were encountered: