Pyinstaller error: 'SystemError: codesign failure!' on macOS

Pyinstaller error: 'SystemError: codesign failure!' on macOS

我制作了一个应用程序,我现在正在 macos 和 windows 上分发(windows 已成功编译)但是当我尝试编译我的应用程序时它不断抛出错误 SystemError: codesign failure! 在 pyinstaller 中我使用 --onefile 标志,我在没有标志的情况下尝试过(python pyinstaller.py app.py,我无法使用 python pyinstaller app.py,因为我被抛出 command not found)。这是完整的错误消息:

326 INFO: Building PKG (CArchive) PKG-00.pkg
4245 WARNING: codesign command (['codesign', '-s', '-', '--force', '--all-architectures', '--timestamp', '/Users/admin/Library/Application Support/pyinstaller/bincache00_py39_64bit/x86_64/adhoc/no-entitlements/lib-dynload/resource.cpython-39-darwin.so']) failed with error code 1!
stdout: ''
stderr: '/Users/admin/Library/Application Support/pyinstaller/bincache00_py39_64bit/x86_64/adhoc/no-entitlements/lib-dynload/resource.cpython-39-darwin.so: invalid or unsupported format for signature\n'
Traceback (most recent call last):
  File "/Users/admin/Documents/Cloud/hero/pyinstaller.py", line 17, in <module>
    run()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/__main__.py", line 126, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 815, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 762, in build
    exec(code, spec_namespace)
  File "/Users/admin/Documents/Cloud/hero/app.spec", line 23, in <module>
    exe = EXE(pyz,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/api.py", line 509, in __init__
    self.pkg = PKG(self.toc, cdict=kwargs.get('cdict', None),
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/api.py", line 208, in __init__
    self.__postinit__()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/datastruct.py", line 159, in __postinit__
    self.assemble()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/api.py", line 274, in assemble
    fnm = checkCache(fnm, strip=self.strip_binaries,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/utils.py", line 391, in checkCache
    osxutils.sign_binary(cachedfile, codesign_identity, entitlements_file)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/utils/osx.py", line 383, in sign_binary
    raise SystemError("codesign failure!")
SystemError: codesign failure!

因为我从来没有为 mac 编译过应用程序,这是我第一次这样做,所以我不知道这到底意味着什么。这是使用 python 3.9.

这似乎是 pyinstaller 执行临时签名的方式的问题,因为代码签名在 4.3 之后的某个时间发生了变化(参见 https://github.com/pyinstaller/pyinstaller/issues/6167)。基于最新的 Big Sur (MacOS 11.5.2) 构建应该可以正常工作,但我假设您使用的是 Catalina 或更早版本。

您可以:

  • 使用 pip uninstall pyinstallerpip install -Iv pyinstaller==4.3 降级到 pyinstaller 4.3,然后照原样重建。

  • 提供证书以自行签署应用程序。

如果您想自己签署应用程序,您可以这样做:

  1. 打开Keychain Access

  2. 转到屏幕顶部的菜单,然后 select Keychain Access > Certificate Assistant > Create a Certificate

  3. 在出现的 window 中将 Certificate Type 更改为 Code Signing , select Create 并记下证书名称

  4. 使用 --codesign-identity <name> 标志构建您的 pyinstaller 源,其中 <name> 是您在步骤 3 中创建的证书的名称。