Repository navigation
Labels
Description
Description of the issue
The app built successfully, however, when I right-click on a file and choose this app to open it, no arguments are received in python script.
However, it works when I manually pass the arguments in Terminal by xxx.app/Contents/MacOS/executable Arg1 Arg2, maybe the kAEOpenDocuments event is not handled correctly?
Context information (for bug reports)
- Output of
pyinstaller --version:4.3 - Version of Python: 3.9.5
- Platform: macOS 11.4
- How you installed Python: pyenv
- Did you also try this on another platform? Does it work there?
This is a macOS-specific issue.
A minimal example program which shows the error
Built a test app using the script & spec file below, right-click on any file and choose test.app to open.
document_event_test.py
#!/usr/bin/env python3
#encoding:utf-8
import sys, os
base = os.path.dirname(sys.argv[0])
with open(os.path.join(base, "logs.txt"), "w+") as f:
if len(sys.argv) > 1:
f.write("arguments received:\n")
for arg in sys.argv[1:]:
f.write(f"{arg}, is file: {os.path.isfile(arg)}\n")
else:
f.write("no arguments received!\n")
spec file:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['document_event_test.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
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='test',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=False,
icon='')
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
upx_exclude=[],
name='test')
app = BUNDLE(coll,
name='test.app',
bundle_identifier="test",
info_plist={
'NSPrincipalClass': 'NSApplication',
'NSAppleScriptEnabled': False,
'CFBundleDocumentTypes': [{
'CFBundleTypeName': 'test_file_types',
'CFBundleTypeExtensions': ['txt', 'std', 'stdf', 'std*'],
'CFBundleTypeRole': 'Viewer'
}],
},
)
Stacktrace / full error message
A log file is generated in the example above, but the content of the log is always no arguments received!.
Activity
rokm commentedon Jun 13, 2021
Sounds like #5436, which also has a proof-of-concept patch that collects Apple events in
onedirmode intoargvbefore starting the python interpreter.noonchen commentedon Jun 13, 2021
Thanks, I'll take a look into that patch. :)
rokm commentedon Jul 24, 2021
Re-opening this issue as support for onedir events processing / argv emulation has been reverted for now due to unforeseen side effects with
tkinter-based applications.rokm commentedon Aug 19, 2021
Support for argv emulation in
onedirmode has been re-enabled in thedevelopbranch via #6089, and will be available in the upcoming PyInstaller 5.x series.This feature is now disabled by default (in both
onefileandonedirmode) and needs to be explicitly opted-in at build time either via--argv-emulationcommand-line switch or usingargv_emulationargument toEXE()in the .spec file.This feature also requires bootloader to be rebuilt, so if you want to try using the
developbranch until 5.0 is released, you will need to rebuild the bootloader yourself.