'Python - build application for mac with pyqt5

Welcome, I have a written program in Python with using PyQt5, a problem lies in that I want to build him to form of one file EXE for Windows which I was able to make with a help of pyinstaller and everything is working well on freshly installed system without any additional installations, but I have a problem with MacOS when I'm trying to do it with pyInstaller or py2app I'm getting errors during the opening of file .app

I've tried those commands:

PyInstaller: pyinstaller --windowed --onefile filename.spec (Link to file .spec is under)

  • When starting application (after a while) is closing without any error

Py2App: python setup.py py2app (Link to file setup.py is under)

  • During performing this command we can see that all libraries of type PyQt5 are added and application have weight of 196 MB so they're there but at startup I'm getting a error report (Link to this report under)

  • If I use command "python setup.py py2app -A' then application is working but it's taking only 222kb and I can assume that on this computer which an application will be running there has to be all libraries. And I want to avoid it.

I want to get one file which I'm sending to 1 person and without any installations of additional libraries application is starting up.

  1. Setup.py:
from setuptools import setup
 
APP=['nazwa_pliku.py']
OPTIONS = {
    'argv_emulation': True,
    'includes': [
        'PyQt5', 'PyQt5.QtCore', 'PyQt5.QtGui', 'PyQt5.QtWidgets',
        'getmac', 'requests', 'shutil', 'zipfile', 'hashlib'
    ]
}
DATA_FILES = [('', ['resources'])]
 
setup(
    app=APP,
    options={'py2app': OPTIONS},
    data_files=DATA_FILES,
    setup_requires=['py2app']
)
  1. PyInstaller (.spec):
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(['nazwa_pliku.py'],
             pathex=['PyQt5', 'PyQt5.QtCore', 'PyQt5.QtGui', 'PyQt5.QtWidgets', 'getmac', 'requests', 'shutil', 'zipfile', 'hashlib'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             hooksconfig={},
             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,
          a.binaries,
          a.zipfiles,
          a.datas,  
          [],
          name='nazwa_pliku',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=False,
          disable_windowed_traceback=False,
          target_arch=None,
          codesign_identity=None,
          entitlements_file=None )
app = BUNDLE(exe,
             name='nazwa_pliku.app',
             icon=None,
             bundle_identifier=None)

  1. Problem report:
Process:               nazwa_pliku [1657]
Path:                  /Users/USER/Downloads/*/nazwa_pliku.app/Contents/MacOS/nazwa_pliku
Identifier:            org.pythonmac.unspecified.nazwa_pliku
Version:               0.0.0 (0.0.0)
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           nazwa_pliku [1657]
User ID:               501

Date/Time:             2022-01-27 08:27:10.807 -0800
OS Version:            macOS 11.0.1 (20B29)
Report Version:        12
Anonymous UUID:        B619491E-F16C-B54A-87DC-CEF880698C90


Time Awake Since Boot: 1200 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff202f8462 __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff20326610 pthread_kill + 263
2   libsystem_c.dylib               0x00007fff20279720 abort + 120
3   QtCore                          0x0000000106d19529 qt_message_fatal(QtMsgType, QMessageLogContext const&, QString const&) + 9
4   QtCore                          0x0000000106d1ac74 QMessageLogger::fatal(char const*, ...) const + 202
5   QtGui                           0x00000001067273d9 QGuiApplicationPrivate::createPlatformIntegration() + 7193
6   QtGui                           0x00000001067273fb QGuiApplicationPrivate::createEventDispatcher() + 27
7   QtCore                          0x0000000106ef91af QCoreApplicationPrivate::init() + 1599
8   QtGui                           0x0000000106721b59 QGuiApplicationPrivate::init() + 57
9   QtWidgets                       0x000000010613cada QApplicationPrivate::init() + 26
10  QtWidgets.abi3.so               0x0000000105db55d8 0x105c6a000 + 1357272
11  sip.cpython-310-darwin.so       0x000000010735175b 0x10734b000 + 26459
12  org.python.python               0x0000000104e2cdf5 0x104d1b000 + 1121781
13  org.python.python               0x0000000104da1fe7 _PyObject_MakeTpCall + 135
14  org.python.python               0x0000000104ee322d 0x104d1b000 + 1868333
15  org.python.python               0x0000000104ed8635 _PyEval_EvalFrameDefault + 19717
16  org.python.python               0x0000000104ed1fe2 0x104d1b000 + 1798114
17  org.python.python               0x0000000104ee316f 0x104d1b000 + 1868143
18  org.python.python               0x0000000104ed8635 _PyEval_EvalFrameDefault + 19717
19  org.python.python               0x0000000104ed1fe2 0x104d1b000 + 1798114
20  org.python.python               0x0000000104ecc2db 0x104d1b000 + 1774299
21  org.python.python               0x0000000104e08ca6 0x104d1b000 + 973990
22  org.python.python               0x0000000104ee316f 0x104d1b000 + 1868143
23  org.python.python               0x0000000104ed8635 _PyEval_EvalFrameDefault + 19717
24  org.python.python               0x0000000104ed1fe2 0x104d1b000 + 1798114
25  org.python.python               0x0000000104ee316f 0x104d1b000 + 1868143
26  org.python.python               0x0000000104ed8635 _PyEval_EvalFrameDefault + 19717
27  org.python.python               0x0000000104ed1fe2 0x104d1b000 + 1798114
28  org.python.python               0x0000000104f4736d 0x104d1b000 + 2278253
29  org.python.python               0x0000000104f46b2d _PyRun_SimpleFileObject + 365
30  org.python.python               0x0000000104f4a5cd PyRun_SimpleFileExFlags + 109
31  org.pythonmac.unspecified.nazwa_pliku   0x0000000102fbbec5 0x102fb7000 + 20165
32  org.pythonmac.unspecified.nazwa_pliku   0x0000000102fba357 main + 257
33  libdyld.dylib                   0x00007fff20341631 start + 1

Thread 1:
0   libsystem_pthread.dylib         0x00007fff20322458 start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib         0x00007fff20322458 start_wqthread + 0

Thread 3:
0   libsystem_pthread.dylib         0x00007fff20322458 start_wqthread + 0

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x0000000112224e00  rcx: 0x00007ffeecc45348  rdx: 0x0000000000000000
  rdi: 0x0000000000000307  rsi: 0x0000000000000006  rbp: 0x00007ffeecc45370  rsp: 0x00007ffeecc45348
   r8: 0x00000000000130a8   r9: 0x00007fff88a9fe68  r10: 0x0000000112224e00  r11: 0x0000000000000246
  r12: 0x0000000000000307  r13: 0x0000000107283658  r14: 0x0000000000000006  r15: 0x0000000000000016
  rip: 0x00007fff202f8462  rfl: 0x0000000000000246  cr2: 0x00007fc002ca6000
  
Logical CPU:     0
Error Code:      0x02000148
Trap Number:     133

Thread 0 instruction stream not available.

Thread 0 last branch register state not available.


Binary Images:
       0x102fb7000 -        0x102fbefff +org.pythonmac.unspecified.nazwa_pliku (0.0.0 - 0.0.0) <ABECB05C-E91D-336E-81D6-4A467D071EE8> /Users/USER/Downloads/*/nazwa_pliku.app/Contents/MacOS/nazwa_pliku
       0x104d1b000 -        0x105092fff +org.python.python (3.10.1, [c] 2001-2021 Python Software Foundation. - 3.10.1) <1071A8DD-3E3D-3958-95BF-BA33F1F82BE5> /Users/USER/Downloads/*/nazwa_pliku.app/Contents/Frameworks/Python.framework/Versions/3.10/Python
       0x105304000 -        0x10530bfff +zlib.cpython-310-darwin.so (0) <87FA5122-1EC5-3030-B8B6-D9F6A4EE2EA8> /Users/USER/Downloads/*/nazwa_pliku.app/Contents/Resources/zlib.cpython-310-darwin.so
       0x105417000 -        0x10542afff +_ctypes.so (0) <A0E1A89B-9D11-36E4-9D58-393EBF9F0D8A> /Users/USER/Downloads/*/nazwa_pliku.app/Contents/Resources/lib/python3.10/lib-dynload/_ctypes.so
       0x105438000 -        0x10543ffff +_struct.so (0) <9399186E-C4E1-3BC6-9DB3-FB26E3BF1AA3> /Users/USER/Downloads/*/nazwa_pliku.app/Contents/Resources/lib/python3.10/lib-dynload/_struct.so
       0x105acc000 -        0x105ae7fff +_pickle.so (0) <FDD8E805-90D8-39A2-838D-B1EFCE959BD7> /Users/USER/Downloads/*/nazwa_pliku.app/Contents/Resources/lib/python3.10/lib-dynload/_pickle.so
       0x105af5000 -        0x105b04fff +_socket.so (0) <92B8B527-7B8F-318E-B2A5-7DF9472FD531> /Users/USER/Downloads/*/nazwa_pliku.app/Contents/Resources/lib/python3.10/lib-dynload/_socket.so
       0x105b11000 -        0x105b1cfff +math.so (0) <66D1DAE5-3559-30ED-826D-9B2143C1BB28> /Users/USER/Downloads/*/nazwa_pliku.app/Contents/Resources/lib/python3.10/lib-dynload/math.so
       0x105b28000 -        0x105b2ffff +select.so (0) <988B1C8F-D008-3880-8A84-32E5B631D225> 

Thanks in advance 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source