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

Library not working in frozen application (e.g. with PyInstaller) #12

Open
MShekow opened this issue Sep 6, 2023 · 5 comments
Open

Comments

@MShekow
Copy link

MShekow commented Sep 6, 2023

I'm trying to build a CLI/Terminal app (frozen with PyInstaller), and it seems that the macos-notifications library starts a new process that calls my CLI again, but with unexpected parameters. Is there any way to work around this problem?

@MShekow MShekow changed the title Library not compatible when freezing application (e.g. with PyInstaller) Library not compatible when frozen application (e.g. with PyInstaller) Sep 6, 2023
@MShekow MShekow changed the title Library not compatible when frozen application (e.g. with PyInstaller) Library not working in frozen application (e.g. with PyInstaller) Sep 6, 2023
@Jorricks
Copy link
Owner

Jorricks commented Sep 6, 2023

Hi @MShekow,

Sorry to hear that. Could you provide a minimal example so I can try to replicate it? I would expect it to work if you wrap all your code around in an if __name__ == "__main__" check

@MShekow
Copy link
Author

MShekow commented Sep 6, 2023

Sure.

main.py:

import argparse

from mac_notifications import client

if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    parser.add_argument("foo")
    parser.add_argument("bar")
    parser.add_argument("baz")
    args = parser.parse_args()
    client.create_notification(title="foo", text="bar")

pyinstaller.spec:

# -*- mode: python ; coding: utf-8 -*-
import sys

block_cipher = None

a = Analysis(
    ['main.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    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='testapp',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='testapp',
)

Run pip install pyinstaller macos-notifications, then just freeze the app with pyinstaller pyinstaller.spec, then run the app with ./dist/testapp/testapp 1 2 3.

Console printout:

usage: testapp [-h] foo bar baz
testapp: error: the following arguments are required: bar, baz
usage: testapp [-h] foo bar baz
testapp: error: the following arguments are required: baz
multiprocessing/resource_tracker.py:104: UserWarning: resource_tracker: process died unexpectedly, relaunching.  Some resources might leak.

Also, very funny, I dare you to instead use the following main.py (if you want to see a logic bomb in action):

from mac_notifications import client

if __name__ == '__main__':
    client.create_notification(title="foo", text="bar")

It gives you a good impression of how it feels to hard-reboot your mac :S

@technoluc
Copy link

Any updates on this? Running into the same issue, I'm expecting a notification but the app just starts a new instance

@Jorricks
Copy link
Owner

Jorricks commented Feb 4, 2024

Thanks again for raising this issue.
Unfortunately, I don't have any updates on this. I am not really aware of the PyInstaller setup and therefore wouldn't know what is breaking it. I am not convinced this is necessarily because of the macOS-notification library, but because of a slightly different Python setup. Therefore, I will keep this issue open to allow anyone to investigate (and find) the issue. However, I hope you can respect my decision to not investigate this myself.

@EndangeredNayla
Copy link

It seems to happen on any frozen python application

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