首页 > 解决方案 > 尝试运行使用 pyinstaller 创建的 Mac 应用程序时,“加载 Python 库时出错”...“找不到图像错误”是什么意思?

问题描述

Mac Big Sur 上的 Python 3.9 使用最新版本的 pyinstaller。

我有一个正常运行的脚本名称Read_CSV_Barplot.py,我想使用 pyinstaller 将其制成 .app。运行 pyinstaller 时,我收到一些警告,但没有错误消息。下面是我的 .spec 文件,我在其中修改了 pathex 以包含存储所需模块的目录 site-packages。尝试在终端上运行生成的 .app 时,我收到以下错误消息,我正在尝试破译:

Error loading Python lib '/Users/fishbacp/Desktop/dist/Read_CSV_Barplot.app/Contents/MacOS/Python': dlopen:
dlopen(/Users/fishbacp/Desktop/dist/Read_CSV_Barplot.app/Contents/MacOS/Python, 10): image not found 

这是 .spec 文件:

block_cipher = None

a = Analysis(['Read_CSV_Barplot.py'],
         pathex=['/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages', '/Users/fishbacp/Desktop'],
         binaries=[],
         datas=[],
         hiddenimports=[],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher,
         noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)
exe = EXE(pyz,
      a.scripts,
      [],
      exclude_binaries=True,
      name='Read_CSV_Barplot',
      debug=False,
      bootloader_ignore_signals=False,
      strip=False,
      upx=True,
      console=True )
coll = COLLECT(exe,
           a.binaries,
           a.zipfiles,
           a.datas,
           strip=False,
           upx=True,
           upx_exclude=[],
           name='Read_CSV_Barplot')

app = BUNDLE(exe,name='Read_CSV_Barplot.app',icon=None,bundle_identifier=None)

我以前从未遇到过这种类型的错误消息,这就是我的困惑所在。

标签: pythonpyinstaller

解决方案


根据https://github.com/pyinstaller/pyinstaller/issues/2047上的帖子,我在我的规范文件中更改exe为在 Bundle 内。coll

尝试运行新应用程序时,我遇到了不同的错误消息,“_tkinter 无法找到。” 我纠正了这个使用brew install python-tk

现在一切正常。


推荐阅读