如何解决使用 pyinstaller 构建 MacOS Python 应用程序时出现 libpython3.9.dylib 图像未找到错误?

Ber*_*ard 7 python macos pyinstaller

我正在 MacOS BigSur 上使用 pyinstaller 构建游戏。它构建正确,但失败并出现“libpython3.9.dylib”“找不到图像”错误(下面是完整错误)

pyinstaller 构建应用程序后,我运行它:dist/gralli_quest.app/Contents/MacOS/gralli_quest

这是启用调试后的输出:

    [22699] PyInstaller Bootloader 3.x
    [22699] LOADER: executable is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS/gralli_quest
    [22699] LOADER: homepath is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS
    [22699] LOADER: _MEIPASS2 is NULL
    [22699] LOADER: archivename is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS/gralli_quest
    [22699] LOADER: Cookie found at offset 0x17CD99D2
    [22699] LOADER: Extracting binaries
    [22699] LOADER: Executing self as child
    [22699] LOADER: set _MEIPASS2 to /var/folders/m7/322j4l357l3chdczl5j75phw0000gn/T/_MEIlAeO5C
    [22699] LOADER: Registering signal handlers
    [22704] PyInstaller Bootloader 3.x
    [22704] LOADER: executable is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS/gralli_quest
    [22704] LOADER: homepath is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS
    [22704] LOADER: _MEIPASS2 is /var/folders/m7/322j4l357l3chdczl5j75phw0000gn/T/_MEIlAeO5C
    [22704] LOADER: archivename is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS/gralli_quest
    [22704] LOADER: Cookie found at offset 0x17CD99D2
    [22704] LOADER: Already in the child - running user`s code.
    [22704] LOADER: Python library: /var/folders/m7/322j4l357l3chdczl5j75phw0000gn/T/_MEIlAeO5C/libpython3.9.dylib
    [22704] Error loading Python lib `/var/folders/m7/322j4l357l3chdczl5j75phw0000gn/T/_MEIlAeO5C/libpython3.9.dylib`: dlopen: dlopen(/var/folders/m7/322j4l357l3chdczl5j75phw0000gn/T/_MEIlAeO5C/libpython3.9.dylib, 10): image not found
    [22699] LOADER: Restoring signal handlers
    [22699] LOADER: freeing args
    [22699] LOADER: returning child exit status 255
    [22699] LOADER: Back to parent (RC: 255)
    [22699] LOADER: Doing cleanup
    [22699] LOADER: Freeing archive status for /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS/gralli_quest
Run Code Online (Sandbox Code Playgroud)

文件 libpython3.9.dylib 确实存在于 pyinstaller 创建的 .app 文件夹中:

ls -al dist/gralli_quest.app/Contents/MacOS/libpython3.9.dylib
-rwxr-xr-x  1 bernard  staff  3831440 Dec 16 17:20 dist/gralli_quest.app/Contents/MacOS/libpython3.9.dylib
Run Code Online (Sandbox Code Playgroud)

我尝试过的事情:

  • 谷歌搜索错误消息的各种变体(令人惊讶的是几乎没有出现)
  • 阅读pyinstaller t-shooting 文档
  • 使用 --enable-shared 和 --enable-framework 选项重建 Python。( env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.9.9)
  • 尝试几个版本的 Python - 3.9.6、3.9.8 和 3.9.9
  • 创建全新的虚拟环境
  • 将 gralli_quest.app 文件夹移到配置了我的 pyenv 的目录之外并从那里运行它
  • 在我的 pyinstaller .spec 文件中启用调试
  • 酿造更新&&酿造升级
  • 将我所有的 pip 软件包升级到最新版本(并不是说这可能解决它)

可以提供我的 .spec 文件或任何其他有帮助的信息。