4

Mac Big Sur, python 3.9, pyinstaller 4.3.

I've seen this question posted elsewhere, e.g. PyInstaller OS X app runs from command line, but not Finder window, but can't quite understand the proposed solutions. I have a Mac .app created using tkinter and pyinstaller that functions fine at the terminal when I type

./dist/MyApplication.app/Contents/MacOS/MyApplication

However, when I double click on the .app in the Finder, the program icon appears briefly on my computer's dock before disappearing. No error message at all.

Here is my .spec file:

block_cipher = None


a = Analysis(['MyApplication.py'],
pathex= 
['/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages', 
'/Users/fishbacp/Desktop'],
 binaries=[],
 datas=[('/Users/fishbacp/Desktop/background.png','.')],
 hiddenimports=['_tkinter','PIL'],
 hookspath=[],
 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,
      [],
      exclude_binaries=True,
      name='MyApplication',
      debug=False,
      bootloader_ignore_signals=False,
      strip=False,
      upx=True,
      console=False )
 coll = COLLECT(exe,
      a.binaries,
      a.zipfiles,
      a.datas,
      strip=False,
      upx=True,
      upx_exclude=[],
      name='MyApplication')
 
 app = 

 BUNDLE(coll,name='MyApplication.app',
 icon='/Users/fishbacp/Desktop/spectrum.ico',
 bundle_identifier=None,
 info_plist={'LSEnvironment': {'LANG': 'de_DE.UTF-8',
 'LC_CTYPE': 'de_DE.UTF-8'}})
fishbacp
  • 1,123
  • 3
  • 14
  • 29

1 Answers1

0

I had same problem (but used one folder mode instead of packaging as an .app), when double click in finder, it will open console and immediately close it. And my case was due to uncaught exception in my program, which failed to load a file from the folder, and correct the path fixed the problem.

from pathlib import Path
# The file path should be relative to the packaged folder path    
file_path = Path(__file__).resolve().with_name("some/path/to/the/file")

It might not be your case but my guess is your program exists due to unexpected condition and that's why it disappears soon, and file path is quite often not handled properly when using PyInstaller. Hope it can help someone.

always_beta
  • 229
  • 4
  • 10