6

I have an application bundle created with PyInstaller on OS X. If I double click the .app bundle in Finder, the application tries to launch, then terminates. No further information is given in the console, other than the application quit.

But if I launch the app executable from the terminal (i.e., ./Contents/MacOS/MyApplication, it works perfectly fine. This seems to be the same behavior experienced in this issue: OSX app built with python quits immediately if app bundle is executed from finder but runs fine from command line, but the marked solution there isn't particularly helpful.

I suspect this is indeed related to an environment or path issue. But I'm not sure how to fix it. Should something be specified in the info.plist file maybe? Any guidance would be greatly appreciated.

Community
  • 1
  • 1
JoshG
  • 6,472
  • 2
  • 38
  • 61

1 Answers1

8

This is most likely due to a bad assumption about the working directory. When you launch from the Finder, the working directory may well be / (depends on OS X version), which is not writeable. If your app writes to the current working directory then you should probably set the working directory to somewhere sensible at startup.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 2
    Interesting. By adding `print os.getcwd()` to my main script, I was able to see that when run from the finder, the working directory indeed is `/`, but when run from the terminal, it's `/Users/MyName/Development/MyApp.app/Contents/MacOS`. I tried setting the working directory to that (i.e., `os.chdir`) just to see what would happen, but still no success. Any thoughts on where the working directory should be set to? And how it should be set? Thank you!! – JoshG Oct 04 '14 at 06:27
  • So long as you set the working directory prior to any file I/O you should be OK - setting it to your home directory would probably be a good place to try first, as that's guaranteed to be writeable. – Paul R Oct 04 '14 at 07:40
  • `os.chdir` to an arbitrary location (script dir) does not work. Window disappears as usual. – kakyo Aug 20 '19 at 03:55
  • Hmm has anyone figured out how to debug this? Would be great to get debug messages from an app that's opened in Finder. – Peter Feb 11 '23 at 02:12