MacOS application does not launch when double clicked but does launch from terminal

applicationsmacospythonterminal

I have written a (GUI) Python script which requires one external file and one module (in a folder). In order to package this script for distribution to others, I am using the following application file structure:

└── Contents
    ├── Info.plist
    └── MacOS
        ├── colors.py
        ├── MainScript.py
        └── <module>
            ├── <module files>

Info.plist looks like this:

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleExecutable</key>
    <string>MainScript.py</string>
</dict>
</plist>

MainScript.py begins with #!/usr/bin/env python3 and was made executable with chmod +x.

When I double click the .app, it momentarily appears in the dock then vanishes. The strange part is that open MyApp.app does work correctly when in the enclosing folder (as well as ./MainScript.py when in the MacOS folder). What am I doing wrong?

Best Answer

One thing I’d try is to use a tool like Platypus to help assemble the application bundle.

It might be easier to narrow down what part of the console log errors are relevant if you can diff your hand crafted app bundle and compare it with the one the tool assembles for you.