Use the latest PyQT6 or PySide6 to build cross-platform desktop applications on Apple silicon chips
I’m using Python in my beloved M1 MacBook Air. Was wondering, can I use Python to build GUI desktop applications in the little power machine? After some errors and trials, I found a way, and it will work for you too.
Make sure you have M1 native running Python 3.9 installed in your M1 machines. If you don’t have it, run this one line command to prepare your environment.
brew install email@example.com
yes only a line command.
PyQt6 and PySide6 are 99.99% Same, The existence of PySide6 is due to licensing. PyQt is being used under GPL or commercial license. Which means you need to open source your code or buy a commercial license for your application which will charge users a fee. While PySide is available under the LGPL license, there is no need to purchase a license for your application.
In the following code sample, PyQt6 and PySide6 are interchangeable. I will be using PySide6 in all sample codes.
Starting from version 6.2, PyQt fully supports Apple Silicon Chip, Just run this command to install PyQt6.
pip install PyQt6
pip install PySide6
Complete. For more information about PyQt6 installation, see this Contact,
By the way, if you want to check what version of PySide you are using, use this code:
# Prints PySide6 version
# Prints the Qt version used to compile PySide6
create a new file
helloworld.py and write the following python code.
from PySide6.QtWidgets import QApplication,QLabel
app = QApplication()
label = QLabel('hello world')
run it now
python helloworld.py in your terminal. You will see a new application pop up like this:
Let’s add a few more elements to the Hello World desktop application.
In the above code, I added a
Window which contains a vertical layout object, and the layout object contains all the widget elements
The first button (btn1) is connected to an event handler –
on_btn1_clicked() So that whenever the button is clicked the event handling function is triggered.
Run it, and you’ll see.
It is unrealistic to ask your application users to install all required packages before installing the application. Therefore, you will need to compile and package all the code in a distributable form. people usually call this process
There are many solutions for compiling PyQt applications. I found
cx_Freeze Works best for Apple silicon chip.
pip install --upgrade cx_Freeze
To compile your PyQt application, in your terminal, run:
cxfreeze -c helloworld.py --target-dir dist
Now, navigate to Dist folder, you can start your APP
- Qt on Apple Silicon: https://www.qt.io/blog/qt-on-apple-silicon
- PyQt5 Tutorial: https://build-system.fman.io/pyqt5-tutorial
- PyQt6 6.2.2: https://pypi.org/project/PyQt6/
- cx_freeze: https://cx-freeze.readthedocs.io/en/latest/index.html
- PyQt5 vs PySide2: https://www.pythonguis.com/faq/pyqt5-vs-pyside2/
- PySide6 official docs: