Qt Application on macOS Mojave

I had a painful time getting a basic Qt5.12 app packaged and deployable on macOS. There is a ton of old irrelevant information out there. This worked as of 2019-01-20

Reference

Setup your environment

Install Qt 5.12 or later.

conda create -n someName python=3.6

source activate someName

pip install PySide2

Build pyinstaller

pyinstaller needs to be built against Mojave to get dark mode

git clone https://github.com/pyinstaller/pyinstaller.git

cd pyinstaller/bootloader

python ./waf distclean all

Go back up to the pyinstaller root

python setup.py install

Now you have pyinstaller with the correct bootloader

Build your application

Using UI Files — Qt for Python

DO NOT LOAD UI FILE DIRECTLY

This caused me hours of pain, just generate a Python class

pyside2-uic mainwindow.ui > ui_mainwindow.py

Try this out in your main.py

import sys  
from PySide2.QtWidgets import QApplication, QMainWindow  
from PySide2.QtCore import QFile  
from ui_mainwindow import Ui_MainWindow

class MainWindow(QMainWindow):  
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

if __name__ == "__main__":  
    app = QApplication(sys.argv)

    window = MainWindow()
    window.show()

    sys.exit(app.exec_())

pyinstaller -w --onefile main.py

This will create directories and a .spec in your working directory. The file you want now is the main.app in the newly created ./build directory.

comments powered by Disqus