PyQt6 pyinstaller应用程序可以构建,但在MacOS(M1芯片)上无法打开。

huangapple go评论149阅读模式
英文:

PyQt6 pyinstaller app builds but wont open MacOS (M1 chip)

问题

我正在尝试使用PyQt6制作一个Python桌面应用程序。我想通过使用pyinstaller将其制作成一个可点击的应用程序,但是当我尝试从Finder运行应用程序时,出现了“应用程序意外关闭”的错误。同样,我也无法从终端运行应用程序,但是在没有pyinstaller的情况下通过我的IDE运行应用程序时,应用程序可以正常工作。

为了测试是否是我的应用程序的问题,我创建了一个新的环境,使用不同版本的Python,并使用了来自PyQt网站的以下简单应用程序代码(https://www.pythonguis.com/tutorials/pyqt6-creating-your-first-window/)

Python版本:3.9
pyinstaller版本:5.13.0
pyqt6版本:6.5.2

尝试启动应用程序并出现崩溃时,将日志发送给苹果会显示以下分段错误:

  1. 异常类型:EXC_BAD_ACCESSSIGSEGV
  2. 异常代码:KERN_INVALID_ADDRESS at 0x0000000000000008
  3. 异常代码:0x00000000000000010x0000000000000008
  4. 终止原因:命名空间SIGNAL,代码11 分段错误:11
  5. 终止进程:exc handler [26876]
  6. VM区域信息:0x8不在任何区域中。在以下区域之前的字节:105553518919672
  7.      区域类型                      起始 - 结束          [VSIZE] PRT/MAX SHRMOD REGION DETAIL
  8.      启动时未使用的空间
  9. --->  
  10.      MALLOC_NANO(保留)600018000000-600020000000 [128.0M] rw-/rwx SM=NUL ...(未分配)
  11. 线程0崩溃::主线程分派队列:com.apple.main-thread
  12. 0    CoreFoundation     0x1922c665c _CFGetNonObjCTypeID + 92
  13. 1    CoreFoundation     0x1921982ec CFBundleCopyBundleURL + 24
  14. 2    QtCore            0x102380a5c QLibraryInfoPrivate::path(QLibraryInfo::LibraryPath, QLibraryInfoPrivate::UsageMode) + 440
  15. 3    QtCore            0x1023810ac QLibraryInfoPrivate::path(QLibraryInfo::LibraryPath, QLibraryInfoPrivate::UsageMode) + 2056
  16. 4    QtCore            0x1023b7470 0x102374000 + 275568
  17. 5    QtCore            0x1023b6a6c 0x102374000 + 273004
  18. 6    QtCore            0x1023b8fd4 0x102374000 + 282580
  19. ...
  20. (以下是长长的错误堆栈,省略部分)

我已经尝试过其他框架,如py2app,更改pyqt版本,更改python版本,在AWS上运行一个新的Ubuntu机器上(新操作系统),并尝试在不同的Mac设备上运行,但仍然没有成功。我还尝试了pyinstaller的所有不同标志,例如--onefile--onedir。我还尝试了Stack Overflow上的建议,使用pyinstaller的开发版本,但这并没有解决问题。非常感谢您提前的帮助!

英文:

I am trying to make a python desktop app with PyQt6. I want to make it into a clickable app by using pyinstaller but I get a "app closed unexpectedly" error when I try to run the app from finder. Equally I cant run the app from terminal either but the app works fine when run through my IDE without pyinstaller.

To test it isnt my app, I have made a fresh environment with different python versions and used the following simple app code from the PyQt website (https://www.pythonguis.com/tutorials/pyqt6-creating-your-first-window/)

Python version 3.9
pyinstaller version 5.13.0
pyqt6 version 6.5.2

When trying to launch the app and it crashes, sending the logs to apple gives a segmentation fault as follows:

  1. Exception Type: EXC_BAD_ACCESS (SIGSEGV)
  2. Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000008
  3. Exception Codes: 0x0000000000000001, 0x0000000000000008
  4. Termination Reason: Namespace SIGNAL, Code 11 Segmentation fault: 11
  5. Terminating Process: exc handler [26876]
  6. VM Region Info: 0x8 is not in any region. Bytes before following region: 105553518919672
  7. REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
  8. UNUSED SPACE AT START
  9. --->
  10. MALLOC_NANO (reserved) 600018000000-600020000000 [128.0M] rw-/rwx SM=NUL ...(unallocated)
  11. Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
  12. 0 CoreFoundation 0x1922c665c _CFGetNonObjCTypeID + 92
  13. 1 CoreFoundation 0x1921982ec CFBundleCopyBundleURL + 24
  14. 2 QtCore 0x102380a5c QLibraryInfoPrivate::path(QLibraryInfo::LibraryPath, QLibraryInfoPrivate::UsageMode) + 440
  15. 3 QtCore 0x1023810ac QLibraryInfoPrivate::path(QLibraryInfo::LibraryPath, QLibraryInfoPrivate::UsageMode) + 2056
  16. 4 QtCore 0x1023b7470 0x102374000 + 275568
  17. 5 QtCore 0x1023b6a6c 0x102374000 + 273004
  18. 6 QtCore 0x1023b8fd4 0x102374000 + 282580
  19. 7 QtCore 0x1023b5c58 QLoggingCategory::QLoggingCategory(char const*, QtMsgType) + 52
  20. 8 QtCore.abi3.so 0x10509cde0 warmUpLocationServices() + 268
  21. 9 QtCore.abi3.so 0x10509f724 _GLOBAL__sub_I_qdarwinpermissionplugin_location.mm + 12
  22. 10 dyld 0x191dd81d8 invocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const::$_0::operator()() const + 168
  23. 11 dyld 0x191e19c60 invocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 172
  24. 12 dyld 0x191e0d1a4 invocation function for block in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 528
  25. 13 dyld 0x191db82d8 dyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const + 296
  26. 14 dyld 0x191e0c1cc dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 192
  27. 15 dyld 0x191e0ecfc dyld3::MachOFile::forEachInitializerPointerSection(Diagnostics&, void (unsigned int, unsigned int, bool&) block_pointer) const + 160
  28. 16 dyld 0x191e19904 dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 432
  29. 17 dyld 0x191dd485c dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 448
  30. 18 dyld 0x191dd4c10 dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 220
  31. 19 dyld 0x191dd8264 dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const::$_1::operator()() const + 112
  32. 20 dyld 0x191dd4d90 dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 304
  33. 21 dyld 0x191df2d58 dyld4::APIs::dlopen_from(char const*, int, void*) + 1440
  34. 22 libpython3.10.dylib 0x100dfa844 _PyImport_FindSharedFuncptr + 296
  35. 23 libpython3.10.dylib 0x100db599c _imp_create_dynamic + 1108
  36. 24 libpython3.10.dylib 0x100ced0fc cfunction_vectorcall_FASTCALL + 200
  37. 25 libpython3.10.dylib 0x100d847dc _PyEval_EvalFrameDefault + 27276
  38. 26 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  39. 27 libpython3.10.dylib 0x100d886d4 call_function + 524
  40. 28 libpython3.10.dylib 0x100d84464 _PyEval_EvalFrameDefault + 26388
  41. 29 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  42. 30 libpython3.10.dylib 0x100d886d4 call_function + 524
  43. 31 libpython3.10.dylib 0x100d8443c _PyEval_EvalFrameDefault + 26348
  44. 32 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  45. 33 libpython3.10.dylib 0x100d886d4 call_function + 524
  46. 34 libpython3.10.dylib 0x100d844d4 _PyEval_EvalFrameDefault + 26500
  47. 35 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  48. 36 libpython3.10.dylib 0x100d886d4 call_function + 524
  49. 37 libpython3.10.dylib 0x100d844d4 _PyEval_EvalFrameDefault + 26500
  50. 38 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  51. 39 libpython3.10.dylib 0x100d886d4 call_function + 524
  52. 40 libpython3.10.dylib 0x100d844d4 _PyEval_EvalFrameDefault + 26500
  53. 41 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  54. 42 libpython3.10.dylib 0x100c9b894 object_vacall + 272
  55. 43 libpython3.10.dylib 0x100c9bab4 _PyObject_CallMethodIdObjArgs + 128
  56. 44 libpython3.10.dylib 0x100db1a28 PyImport_ImportModuleLevelObject + 1284
  57. 45 libpython3.10.dylib 0x100d770b4 builtin___import__ + 124
  58. 46 libpython3.10.dylib 0x100cec3a0 cfunction_call + 80
  59. 47 libpython3.10.dylib 0x100c9998c _PyObject_MakeTpCall + 612
  60. 48 libpython3.10.dylib 0x100c9ac48 _PyObject_CallFunctionVa + 776
  61. 49 libpython3.10.dylib 0x100c9a918 PyObject_CallFunction + 64
  62. 50 libpython3.10.dylib 0x100db13e8 PyImport_Import + 552
  63. 51 libpython3.10.dylib 0x100db27e0 PyImport_ImportModule + 60
  64. 52 sip.cpython-310-darwin.so 0x100be1754 sip_api_export_module + 88
  65. 53 QtWidgets.abi3.so 0x1017c1188 PyInit_QtWidgets + 276
  66. 54 libpython3.10.dylib 0x100db59ec _imp_create_dynamic + 1188
  67. 55 libpython3.10.dylib 0x100ced0fc cfunction_vectorcall_FASTCALL + 200
  68. 56 libpython3.10.dylib 0x100d847dc _PyEval_EvalFrameDefault + 27276
  69. 57 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  70. 58 libpython3.10.dylib 0x100d886d4 call_function + 524
  71. 59 libpython3.10.dylib 0x100d84464 _PyEval_EvalFrameDefault + 26388
  72. 60 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  73. 61 libpython3.10.dylib 0x100d886d4 call_function + 524
  74. 62 libpython3.10.dylib 0x100d8443c _PyEval_EvalFrameDefault + 26348
  75. 63 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  76. 64 libpython3.10.dylib 0x100d886d4 call_function + 524
  77. 65 libpython3.10.dylib 0x100d844d4 _PyEval_EvalFrameDefault + 26500
  78. 66 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  79. 67 libpython3.10.dylib 0x100d886d4 call_function + 524
  80. 68 libpython3.10.dylib 0x100d844d4 _PyEval_EvalFrameDefault + 26500
  81. 69 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  82. 70 libpython3.10.dylib 0x100d886d4 call_function + 524
  83. 71 libpython3.10.dylib 0x100d844d4 _PyEval_EvalFrameDefault + 26500
  84. 72 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  85. 73 libpython3.10.dylib 0x100c9b894 object_vacall + 272
  86. 74 libpython3.10.dylib 0x100c9bab4 _PyObject_CallMethodIdObjArgs + 128
  87. 75 libpython3.10.dylib 0x100db1a28 PyImport_ImportModuleLevelObject + 1284
  88. 76 libpython3.10.dylib 0x100d770b4 builtin___import__ + 124
  89. 77 libpython3.10.dylib 0x100cec3a0 cfunction_call + 80
  90. 78 libpython3.10.dylib 0x100c9a3a0 _PyObject_Call + 148
  91. 79 libpython3.10.dylib 0x100d847dc _PyEval_EvalFrameDefault + 27276
  92. 80 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  93. 81 libpython3.10.dylib 0x100d886d4 call_function + 524
  94. 82 libpython3.10.dylib 0x100d844d4 _PyEval_EvalFrameDefault + 26500
  95. 83 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  96. 84 libpython3.10.dylib 0x100c9b894 object_vacall + 272
  97. 85 libpython3.10.dylib 0x100c9bab4 _PyObject_CallMethodIdObjArgs + 128
  98. 86 libpython3.10.dylib 0x100db1ba0 PyImport_ImportModuleLevelObject + 1660
  99. 87 libpython3.10.dylib 0x100d82b40 _PyEval_EvalFrameDefault + 19952
  100. 88 libpython3.10.dylib 0x100d7d444 _PyEval_Vector + 2056
  101. 89 libpython3.10.dylib 0x100d7cc0c PyEval_EvalCode + 120
  102. 90 main 0x10074c8ec 0x100748000 + 18668
  103. 91 main 0x10074cf10 0x100748000 + 20240
  104. 92 dyld 0x191dbbf28 start + 2236

I have tried other frameworks such as py2app, changing pyqt versions, changing python versions, running on a ubuntu machine (new OS) on aws and tried on a different mac device and still no luck. I have also tried all the different flags from pyinstaller e.g --onefile and --onedir. I have also seen and tried the stack overflow suggestion to use the dev version of pyinstaller but this did not resolve the issue. Any help would be massively appreciated - thanks in advance!

答案1

得分: 2

在经过了很多搜索后,最终导致我找到答案的关键术语是 Segmentation fault: 11。一旦找到了这个,对我起作用的修复方法来自以下帖子(https://github.com/pyinstaller/pyinstaller/issues/7789):

  1. pip uninstall pyinstaller
  2. PYINSTALLER_COMPILE_BOOTLOADER=1 pip install git+https://github.com/pyinstaller/pyinstaller.git@develop

我希望这对其他遇到相同问题的人有所帮助!

英文:

After much searching, the key term that led me to the answer ended up being the Segmentation fault: 11. Once this was found then the fix that worked for me came from the following post (https://github.com/pyinstaller/pyinstaller/issues/7789) which was:

  1. pip uninstall pyinstaller
  2. PYINSTALLER_COMPILE_BOOTLOADER=1 pip install git+https://github.com/pyinstaller/pyinstaller.git@develop

I hope this helps if anyone else runs into the same issue!

huangapple
  • 本文由 发表于 2023年8月9日 18:35:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76866923.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定