ronaldoussoren / py2app

py2app is a Python setuptools command which will allow you to make standalone Mac OS X application bundles and plugins from Python scripts.
Other
342 stars 36 forks source link

App Fails To Launch But Works From Terminal #463

Open bradyjensen1115 opened 2 years ago

bradyjensen1115 commented 2 years ago

I've done a fair bit of poking around trying to resolve this but can't seem to make any progress. I have an application that works well when run through the debugger. I then followed the steps and used py2app to generate the application. It processes completely but when when I try to launch the app directly I get the generic 'Launch Error' message. When I launch the application from dist in the terminal, it runs without issue.

Any ideas what might be going on or what I can do to see more details about what is causing this to fail?

mlandesman commented 1 year ago

Same problem on MacOS Ventura (production) with Python3. First time building Python and py2app so assumed it was me but the app runs in the IDE and runs in the Terminal window from dist folder. Generic Launch error from Finder.

What is interesting to me is that my app uses tkinter and pops a window up before the launch error. Also, the app reads an ugly CSV file, processes it and creates a new CSV file. That file IS created on my Desktop (as designed) but is empty. It fill properly from the command line interface. That tells me it isn't a "launch" error but an executable/run time error.

Has anyone else seen this or have any recommendations? The app is for my own use so I don't need to package for distribution on other systems.

mlandesman commented 1 year ago

Well, I broke down my code to the smallest component and it appears to be with the "for" loop through the CSV file. In the code below, I can open and parse the file but I can't iterate using the for loop. That causes the Terminate on startup but works when run from the dist CLI and inside the IDE PyCharm. It does not appear to be access issues as removing the for loop works. Any thoughts?

`import csv

with open('/Users/michael/Desktop/exportCsvCheckAccountMovementList.action.csv', mode='r') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') for row in csv_reader: print (row[0]) `

mlandesman commented 1 year ago

In the words of Emily Latilla, "Nevermind". It turns out the problem is in the data, not the code but it is still a problem for py2app. The data file from a mexican bank contains diacritics (accented characters). These work just in from the CLI and from inside the interpreter but crash the .APP file created by py2app. I wrote a small routine to clean the file first (using standard open().read() command but that crashes also so it is not the csv.reader function. If I clean the file first (using the same code in the interpreter to generate a clean file) then run the .APP again it works perfectly. It just can't open and process the quoted characters. Any suggestions would be greatly appreciated. Perhaps there is an environment change to change the language or character set unless py2app only works on English-language code and data.

pavlinbl4 commented 1 year ago

when when I try to launch the app directly I get the generic 'Launch Error' message. When I launch the application from dist in the terminal, it runs without issue. ( window - is application name)

Process: window [4743] Path: /Volumes/VOLUME/*/window.app/Contents/MacOS/window Identifier: org.pythonmac.unspecified.window Version: 0.0.0 (0.0.0) Code Type: X86-64 (Native) Parent Process: launchd [1] User ID: 501

Date/Time: 2023-05-09 10:34:25.1827 +0300 OS Version: macOS 12.6.3 (21G419) Report Version: 12 Anonymous UUID:

Time Awake Since Boot: 11000 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

Application Specific Backtrace 0: 0 CoreFoundation 0x00007ff815aa7773 exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007ff815807bc3 objc_exception_throw + 48 2 Foundation 0x00007ff816953d03 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 267 3 AppKit 0x00007ff8184571c9 -[NSMenuItem initWithTitle:action:keyEquivalent:] + 363 4 libtk8.6.dylib 0x000000010d401fec TkMacOSXInitMenus + 984 5 libtk8.6.dylib 0x000000010d3fe431 TkMacOSXClearMenubarActive + 399 6 libtk8.6.dylib 0x000000010d3ff82a TkpSetMainMenubar + 166 7 libtk8.6.dylib 0x000000010d37de26 TkSetWindowMenuBar + 777 8 libtk8.6.dylib 0x000000010d3770e2 TkToplevelWindowForCommand + 1607 9 libtk8.6.dylib 0x000000010d376d00 TkToplevelWindowForCommand + 613 10 libtcl8.6.dylib 0x000000010d1fbc71 TclNRRunCallbacks + 79 11 libtcl8.6.dylib 0x000000010d1fcdc4 Tcl_EvalEx + 1888 12 libtcl8.6.dylib 0x000000010d1fc67e Tcl_EvalEx + 26 13 libtk8.6.dylib 0x000000010d350e42 Tk_CreateConsoleWindow + 810 14 libtk8.6.dylib 0x000000010d3fb684 TkpInit + 620 15 libtk8.6.dylib 0x000000010d36f387 Tk_Init + 2412 16 _tkinter.so 0x000000010c7fc74b PyInit__tkinter + 22299 17 _tkinter.so 0x000000010c7fc439 PyInittkinter + 21513 18 _tkinter.so 0x000000010c7fc1de PyInittkinter + 20910 19 _tkinter.so 0x000000010c7fbe04 PyInit__tkinter + 19924 20 Python 0x000000010bb6fb63 PyCFunction_New + 451 21 Python 0x000000010bc37c3f _PyEval_EvalFrameDefault + 59967 22 Python 0x000000010bc3dd50 _PyEval_EvalFrameDefault + 84816 23 Python 0x000000010bc3ae2a _PyEval_EvalFrameDefault + 72746 24 Python 0x000000010bc3dd50 _PyEval_EvalFrameDefault + 84816 25 Python 0x000000010bb0a6a0 _PyObject_FastCallDictTstate + 96 26 Python 0x000000010bb98445 PyType_GenericNew + 10693 27 Python 0x000000010bb8e6ba _PyTuple_DebugMallocStats + 1786 28 Python 0x000000010bb0a3e1 _PyObject_MakeTpCall + 129 29 Python 0x000000010bc37d37 _PyEval_EvalFrameDefault + 60215 30 Python 0x000000010bc27eba PyEval_EvalCode + 282 31 Python 0x000000010bc22833 PyInittokenize + 54019 32 Python 0x000000010bb6fc94 PyCFunction_New + 756 33 Python 0x000000010bc37c3f _PyEval_EvalFrameDefault + 59967 34 Python 0x000000010bc27eba PyEval_EvalCode + 282 35 Python 0x000000010bcade18 _PyRun_SimpleFileObject + 2184 36 Python 0x000000010bcad6b4 _PyRun_SimpleFileObject + 292 37 Python 0x000000010bcb1960 PyRun_SimpleFileExFlags + 112 38 window 0x0000000109119ec5 main + 7279 39 window 0x0000000109118357 main + 257 40 dyld 0x0000000111b2352e start + 462

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libsystem_kernel.dylib 0x7ff81592f00e pthread_kill + 10 1 libsystem_pthread.dylib 0x7ff8159651ff pthread_kill + 263 2 libsystem_c.dylib 0x7ff8158b0d24 abort + 123 3 libc++abi.dylib 0x7ff815921082 abort_message + 241 4 libc++abi.dylib 0x7ff81591225d demangling_terminate_handler() + 266 5 libobjc.A.dylib 0x7ff81580ee11 _objc_terminate() + 96 6 libc++abi.dylib 0x7ff8159204a7 std::terminate(void (*)()) + 8 7 libc++abi.dylib 0x7ff815922d05 cxxabiv1::failed_throw(cxxabiv1::__cxa_exception*) + 27 8 libc++abi.dylib 0x7ff815922ccc __cxa_throw + 116 9 libobjc.A.dylib 0x7ff815807cc1 objc_exception_throw + 302 10 Foundation 0x7ff816953d03 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 267 11 AppKit 0x7ff8184571c9 -[NSMenuItem initWithTitle:action:keyEquivalent:] + 363 12 libtk8.6.dylib 0x10d401fec +[NSMenuItem(TKUtils) itemWithSubmenu:] + 71 13 libtk8.6.dylib 0x10d3fe431 -[TKApplication(TKMenu) tkSetMainMenu:] + 257 14 libtk8.6.dylib 0x10d3ff82a TkpSetMainMenubar + 166 15 libtk8.6.dylib 0x10d37de26 TkSetWindowMenuBar + 777 16 libtk8.6.dylib 0x10d3770e2 ConfigureFrame + 262 17 libtk8.6.dylib 0x10d376d00 FrameWidgetObjCmd + 545 18 libtcl8.6.dylib 0x10d1fbc71 TclNRRunCallbacks + 79 19 libtcl8.6.dylib 0x10d1fcdc4 TclEvalEx + 1856 20 libtcl8.6.dylib 0x10d1fc67e Tcl_EvalEx + 26 21 libtk8.6.dylib 0x10d350e42 Tk_CreateConsoleWindow + 810 22 libtk8.6.dylib 0x10d3fb684 TkpInit + 620 23 libtk8.6.dylib 0x10d36f387 Initialize + 2402 24 _tkinter.so 0x10c7fc74b Tcl_AppInit + 91 25 _tkinter.so 0x10c7fc439 Tkapp_New + 585 26 _tkinter.so 0x10c7fc1de _tkinter_create_impl + 222 27 _tkinter.so 0x10c7fbe04 _tkinter_create + 164 28 Python 0x10bb6fb63 cfunction_vectorcall_FASTCALL + 83 29 Python 0x10bc37c3f _PyEval_EvalFrameDefault + 59967 30 Python 0x10bc3dd50 _PyEval_Vector + 128 31 Python 0x10bc3ae2a _PyEval_EvalFrameDefault + 72746 32 Python 0x10bc3dd50 _PyEval_Vector + 128 33 Python 0x10bb0a6a0 _PyObject_FastCallDictTstate + 96 34 Python 0x10bb98445 slot_tp_init + 181 35 Python 0x10bb8e6ba type_call + 122 36 Python 0x10bb0a3e1 _PyObject_MakeTpCall + 129 37 Python 0x10bc37d37 _PyEval_EvalFrameDefault + 60215 38 Python 0x10bc27eba PyEval_EvalCode + 282 39 Python 0x10bc22833 builtin_exec + 483 40 Python 0x10bb6fc94 cfunction_vectorcall_FASTCALL_KEYWORDS + 68 41 Python 0x10bc37c3f _PyEval_EvalFrameDefault + 59967 42 Python 0x10bc27eba PyEval_EvalCode + 282 43 Python 0x10bcade18 pyrun_file + 248 44 Python 0x10bcad6b4 _PyRun_SimpleFileObject + 292 45 Python 0x10bcb1960 PyRun_SimpleFileExFlags + 112 46 window 0x109119ec5 py2app_main + 5481 47 window 0x109118357 main + 257 48 dyld 0x111b2352e start + 462

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

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

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

Thread 4: 0 libsystem_kernel.dylib 0x7ff815930d5a __select + 10 1 libtcl8.6.dylib 0x10d2ec8b8 NotifierThreadProc + 880 2 libsystem_pthread.dylib 0x7ff8159654e1 _pthread_start + 125 3 libsystem_pthread.dylib 0x7ff815960f6b thread_start + 15

Thread 0 crashed with X86 Thread State (64-bit): rax: 0x0000000000000000 rbx: 0x0000000111b9e600 rcx: 0x00007ff7b6de5548 rdx: 0x0000000000000000 rdi: 0x0000000000000103 rsi: 0x0000000000000006 rbp: 0x00007ff7b6de5570 rsp: 0x00007ff7b6de5548 r8: 0x00007ff7b6de5410 r9: 0x00007ff815923f9b r10: 0x0000000000000000 r11: 0x0000000000000246 r12: 0x0000000000000103 r13: 0x0000003000000008 r14: 0x0000000000000006 r15: 0x0000000000000016 rip: 0x00007ff81592f00e rfl: 0x0000000000000246 cr2: 0x00007ff8570e8f58

Logical CPU: 0 Error Code: 0x02000148 Trap Number: 133

Binary Images: 0x7ff815927000 - 0x7ff81595efff libsystem_kernel.dylib () /usr/lib/system/libsystem_kernel.dylib 0x7ff81595f000 - 0x7ff81596afff libsystem_pthread.dylib () /usr/lib/system/libsystem_pthread.dylib 0x7ff81582f000 - 0x7ff8158b7fff libsystem_c.dylib () /usr/lib/system/libsystem_c.dylib 0x7ff815911000 - 0x7ff815926fff libc++abi.dylib () /usr/lib/libc++abi.dylib 0x7ff8157f2000 - 0x7ff81582bfff libobjc.A.dylib () <4d9b0dca-7151-3875-b98e-b255db8267a8> /usr/lib/libobjc.A.dylib 0x7ff816828000 - 0x7ff816be4fff com.apple.Foundation (6.9) /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation 0x7ff818425000 - 0x7ff8192b4fff com.apple.AppKit (6.9) <11be8778-f5e5-3ccb-bcc3-10ffea3bf44b> /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit 0x10d339000 - 0x10d440fff libtk8.6.dylib () <31da200f-d034-3bee-9673-53da7054631b> /Volumes/VOLUME//window.app/Contents/Frameworks/libtk8.6.dylib 0x10d1e9000 - 0x10d30cfff libtcl8.6.dylib () <0cf0f829-43bc-3847-86e5-aa783391c315> /Volumes/VOLUME//window.app/Contents/Frameworks/libtcl8.6.dylib 0x10c7f6000 - 0x10c7fdfff _tkinter.so () /Volumes/VOLUME//window.app/Contents/Resources/lib/python3.11/lib-dynload/_tkinter.so 0x10ba67000 - 0x10be46fff org.python.python (3.11.0, (c) 2001-2021 Python Software Foundation.) <6b965100-5ab3-35a6-adc9-3e7eb71eda7a> /Volumes/VOLUME//window.app/Contents/Frameworks/Python.framework/Versions/3.11/Python 0x109115000 - 0x10911cfff org.pythonmac.unspecified.window (0.0.0) /Volumes/VOLUME//window.app/Contents/MacOS/window 0x111b1e000 - 0x111b89fff dyld () <006a3e6f-3cd3-34d9-b0f2-ed6bd67a95a6> /usr/lib/dyld 0x7ff8159ac000 - 0x7ff815eaefff com.apple.CoreFoundation (6.9) <93c48919-68af-367e-9a67-db4159bc962c> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation

External Modification Summary: Calls made by other processes targeting this process: task_for_pid: 0 thread_create: 0 thread_set_state: 0 Calls made by this process: task_for_pid: 0 thread_create: 0 thread_set_state: 0 Calls made by all processes on this machine: task_for_pid: 0 thread_create: 0 thread_set_state: 0

VM Region Summary: ReadOnly portion of Libraries: Total=938.8M resident=0K(0%) swapped_out_or_unallocated=938.8M(100%) Writable regions: Total=1.5G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.5G(100%)

                            VIRTUAL   REGION 

REGION TYPE SIZE COUNT (non-coalesced) =========== ======= ======= Accelerate framework 256K 2 Activity Tracing 256K 1 CG backing stores 960K 4 ColorSync 212K 24 Kernel Alloc Once 8K 1 MALLOC 235.2M 39 MALLOC guard page 48K 11 MALLOC_MEDIUM (reserved) 720.0M 6 reserved VM address space (unallocated) MALLOC_NANO (reserved) 384.0M 1 reserved VM address space (unallocated) ObjC additional data 15K 1 STACK GUARD 56.0M 5 Stack 9820K 5 VM_ALLOCATE 119.1M 39 VM_ALLOCATE (reserved) 96.0M 1 reserved VM address space (unallocated) CTF 756 1 DATA 20.8M 351 DATA_CONST 11.8M 168 __DATA_DIRTY 534K 97 FONT_DATA 4K 1 LINKEDIT 649.7M 68 TEXT 289.1M 364 __UNICODE 592K 1 dyld private memory 1024K 1 mapped file 156.2M 19 shared memory 780K 16 =========== ======= ======= TOTAL 2.7G 1227 TOTAL, minus reserved VM space 1.5G 1227

ExamDay commented 10 months ago

Turn off argv_emulation in your setup.py. The step that fails here is: NSMenuItem initWithTitle:action:keyEquivalent: which is called by Tkinter which gets confused by argv_emulation.

ogdendigital commented 9 months ago

Turn off argv_emulation in your setup.py. The step that fails here is: NSMenuItem initWithTitle:action:keyEquivalent: which is called by Tkinter which gets confused by argv_emulation.

Thanks @ExamDay! Worked for me 👍