I'm attempting to package up a Python (3.8 in a venv, within PyCharm) as a distributable macOS .app bundle. I've done this with Tkinter before, under macOS Catalina, however this project is in PySide2 (5.15.2) and developed under Big Sur 11.1 on an M1 chip.
MRE (saved as main.py in my environment):
from PySide2.QtWidgets import QApplication, QMainWindow, QLabel
app = QApplication()
window = QMainWindow()
label = QLabel('foo')
window.setCentralWidget(label)
window.show()
app.exec_()
Running this from PyCharm correctly renders the window as expected. However after packaging it via PyInstaller, executing both the .py (from the /dist folder) or the .app bundle created fails to render any UI. It appears the app is launched properly, as it appears in the Dock and the process is unresponsive in Activity Monitor (at ~98% CPU usage). There is no error printed to the console nor noted anywhere.
The Pyinstaller command is fairly basic: pyinstaller --windowed main.py
And the .spec generated:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['main.py'],
pathex=['/Users/ben/PycharmProjects/pythonProject'],
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='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='main')
app = BUNDLE(coll,
name='main.app',
icon=None,
bundle_identifier=None)
I have found the following:
- https://forums.macrumors.com/threads/pyqt5-and-big-sur.2260773/
- Apps not popping up on macOS Big Sur 11.0.1
Additionally, I've tested this with under PyQt5 instead (and provided QApplication() with an empty set of args, app = QApplication([])
, as > 0 args are required. That was successful; a UI was built as expected. I've also provided PySide2's QApplication with sys.argv, but there was no UI generated.
However, the fixes listed in the links above indicate to add to the system environment. As I'm only encountering issues with the dist executables, I'm not sure how to proceed getting this into the distributable; is there a change to the .spec I can insert to set the environment variable on the machines I'll be installing this on? Am I missing something entirely? Is this just another artifact of the Big Sur library reference issues (as noted in those links)?