Search code examples
python-3.xmacospyinstaller

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


I have made an application that I am now distributing on macos and windows (windows successfully compiled) but when I try to compile my app it keeps throwing the error SystemError: codesign failure! In pyinstaller I am using the --onefile flag, and I have tried it without the flag (python pyinstaller.py app.py, I could not use python pyinstaller app.py as I was thrown command not found). This is the full error message:

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!

Since I have never compiled an app for mac and this is my first time doing it, I have no idea what this really means. This is using python 3.9.


Solution

  • This seems to be an issue with the way pyinstaller performs ad-hoc signing since codesigning changed sometime after 4.3 (see https://github.com/pyinstaller/pyinstaller/issues/6167). Building on the latest Big Sur (MacOS 11.5.2) should work fine but I assume you're on Catalina or earlier.

    You can either:

    • Downgrade to pyinstaller 4.3 with pip uninstall pyinstaller and pip install -Iv pyinstaller==4.3 and then rebuild as you were.

    or

    • Provide a certificate to sign the app yourself.

    If you want to sign the app yourself you can do so like so:

    1. Open Keychain Access

    2. Go to the menu at the top of the screen and select Keychain Access > Certificate Assistant > Create a Certificate

    3. In the window that appears change Certificate Type to Code Signing , select Create and note the name of the certificate

    4. Build your pyinstaller source with the --codesign-identity <name> flag where <name> is the name of the certificate you created in step 3.