I have attempted to convert my python program into a .app using PyInstaller. The actual code runs fine through IDLE, but everytime I try and run the newly converted .app, it clo
After many hours scouring/tinkering, I think I have found a solution!!
I have been having the same issue. This is defined by a Pyinstaller build that works fine on Windows and Linux, but closes immediately after building on Mac. Like you, the Mac build app closes after opening, but if you navigate through the app folder and open the Unix Executable directly it runs flawlessly. Your spec file looks perfect to me.
For me I traced the issue down to my program having to write files to the disk, whether it be creating a log file, or creating a shelf file (which I use for save date). When you run a pyinstaller build Macs will do all their run-time things in a random temp folder. For some reason Macs can find their way to the correct run-time temp folder when run from the unix executable, but get lost when run from the app. You COULD use _meipass to guide your log/shelf file (or whatever) to the correct temp folder, but this causes other problems. Some newer macs don't have permission to write there, and additionally you get a new temp folder every time you open the program, making it useless for logs or saves.
To resolve this issue use the following snippet:
import sys
import os
if getattr(sys, 'frozen', False):
Current_Path = os.path.dirname(sys.executable)
else:
Current_Path = str(os.path.dirname(__file__))
And then connect it to your log/shelf/save file names accordingly:
shelfFile = shelve.open(os.path.join(Current_Path, 'example_data'))
This solution will make any created file drop right next to your Unix Executable in the Mac app bundle, and NOT in the random temp file. Macs will find the location properly, and you will be able to reference the same file every time you open the program. My program also now opens from double clicking the app as intended.
I've been coming back and trying to solve this problem for MONTHS. Hopefully someone else finds this useful.