Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS bundle works only if executable is launched directly #1228

Open
Merkwurdichliebe opened this issue Sep 1, 2021 · 4 comments
Open

macOS bundle works only if executable is launched directly #1228

Merkwurdichliebe opened this issue Sep 1, 2021 · 4 comments

Comments

@Merkwurdichliebe
Copy link

Merkwurdichliebe commented Sep 1, 2021

I compile an executable macOS application bundle successfully, but it only launches if I go into the .app/Contents/MacOS/ manually (e.g. with "Show Package Contents") and double click the executable.

If I double-click the .app bundle itself in the Finder, nothing happens.

If I try running the .app bundle from the Terminal (with open myapp.app), I get:

LSOpenURLsWithRole() failed with error -10810 for the file /Users/foo/myapp.app

My setup:

  • macOS Catalina 10.15.7, Intel Quad-Core i7
  • cx_Freeze version 6.7
  • Python version 3.9

setup.py

Again, this compiles successfully):

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
build_options_exe = {
    'include_files': [
        ('configmine.yml', 'configmine.yml'),
        ('config.yml', 'config.yml'),
        ('data/locations.json', 'data/locations.json')
        ]
}

build_options_app = {
    'iconfile': 'resources/icon-app.icns',
    'bundle_name': 'myapp'
    }

build_options_dmg = {
    'volume_label': 'myapp'
}

import sys
base = 'Win32GUI' if sys.platform == 'win32' else None

executables = [
    Executable(
        'myapp.py',
        base=base, 
        target_name='myapp')
]

setup(name='myapp',
      version='1.0',
      description='',
      options={
          'build_exe': build_options_exe,
          'bdist_mac': build_options_app,
          'bdist_dmg': build_options_dmg
          },
      executables=executables)

I am running the exact same setup used for another project which is much simpler, with no data files and no includes. It works as expected, on the same machine. So I feel this might be related to the included data files. I am using the unmodified function from the FAQ, which successfully locates the data files based on context. I've checked my filenames in both frozen and unfrozen context, and they are correctly built. If they weren't, the app wouldn't launch at all anyway.

Console log from failed launch

When using open myapp.app in Terminal (I have copied only the entries starting from "invalidating assertion".

default	07:34:34.156884+0200	runningboardd	Invalidating assertion 359-208-13350 (target:executable<myapp(501)>) from originator 208
default	07:34:34.347306+0200	runningboardd	[executable<myapp(501)>:15202] Death sentinel fired!
default	07:34:34.350142+0200	loginwindow	-[PersistentAppsSupport applicationQuit:] | for app:myapp, _appTrackingState = 2
default	07:34:34.350169+0200	loginwindow	-[PersistentAppsSupport applicationQuit:] | App: myapp, quit, updating active tracking timer
default	07:34:34.350482+0200	runningboardd	Invalidating assertion 359-208-13351 (target:executable<myapp(501)>) from originator 208
default	07:34:34.459194+0200	runningboardd	[executable<myapp(501)>:15202] Ignoring jetsam update because this process is not memory-managed
default	07:34:34.459213+0200	runningboardd	[executable<myapp(501)>:15202] Ignoring suspend because this process is not lifecycle managed
default	07:34:34.459268+0200	runningboardd	[executable<myapp(501)>:15202] Ignoring GPU update because this process is not GPU managed
default	07:34:34.459595+0200	runningboardd	Removing process: [executable<myapp(501)>:15202]
default	07:34:34.462423+0200	runningboardd	Removing assertions for terminated process: [executable<myapp(501)>:15202]

The log from the successful launch (via the executable in MacOS) also has "invalidating assertion" but then displays many more entries before displaying the UI.

I've tried this with the data files inside the MacOS folder or the Resources folder, the result is identical.

Thanks for your help.

@drnlm
Copy link

drnlm commented Sep 9, 2021

As far as I can determine, the -10810 error code is due to something trying to access stdout, stderr and/or stdin - this can be from one of the underlying libraries, so it may not be obvious that it's happening.

The workaround I've found is explicitly launching the application in the macos terminal - from pyinstaller/pyinstaller#5154 (comment) . I have not had a chance to look at how to automatically apply this workaround, but it's a simple manual fix to the app produced by cx_Freeze .

@Merkwurdichliebe
Copy link
Author

As I wrote above, it depends on what you mean by launching the app in the Terminal:

  • open my.app displays the error in the Terminal and fails to launch the app.
  • `myapp.app/Contents/MacOS/myapp' launches the app successfully.

I've read the entire pyinstaller issue#5154 page and I can confirm that there are neither print nor input statements in my code. I don't know if that's the case in the libraries. I'm only using PySide6 and PyYAML.

Qt does output to the Terminal the following line (which is another Qt annoyance discussed in many other types of context not specific to Python):

qt.qpa.fonts: Populating font family aliases took 261 ms. Replace uses of missing font family "H" with one that exists to avoid this cost. 

I've removed the line in my code that loads the font (which causes the output above), and I've also disabled any debug messages from the logging module. After recompilation, I can confirm that the app doesn't output anything to the Terminal anymore, but still won't run by entering open myapp.app or by double-clicking its icon.

The strange part is that the -10810 error code is produced before my Python code even gets processed. I've modified my main() entry point to look like the following, and no log file is even produced.

def main():
    try:
        app = Beacon2Map()
        app.setWindowIcon(QIcon(QPixmap(cfg.icon['app'])))
        window = MainWindow()
        window.show()
    except Exception as e:
        with open('/Users/me/Desktop/error.log', 'w') as f:
            f.write(f"{e}\n")
    else:
        with open('/Users/me/Desktop/error.log', 'w') as f:
            f.write("no errors")
    sys.exit(app.exec())

if __name__ == '__main__':
    main()

However, the log file is produced — showing "no errors" — if I (again, successfully) run the app from the Terminal.

@dseyit
Copy link

dseyit commented May 11, 2022

Hi,

I have the same issue with my app, it runs in terminal but does not run when bundled in .app format,

I realized xprotectservice runs together with the .app,

Can antimalware protection of mac os be preventing it from running?

@Willy-JL
Copy link

Willy-JL commented Jul 22, 2022

I have this exact same issue, but I've noticed something peculiar: if I first move the .app bundle to /Applications and then run it by double clicking, or by using the launchpad, it works fine. It "only" breaks if launching from anywhere else on the system outside of /Applications.

EDIT: this is just speculation cos I'm not a macOS user and my knowledge about it is very limited, but could it be that apps inside /Applications maybe get some special logging treatment, therefore they actually have proper stdout and stderr, although not directly visible to the user?

EDIT 2: I've played around with it a bit more with some debug prints and it seems to crash on me when it gets to redirecting the console to file, so yeah it's definitely something to do with stdout and stderr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants