-
Notifications
You must be signed in to change notification settings - Fork 1
Home
This Wiki is for you if you want to develop cross-platform (Windows/Mac/Linux) applications with PyQt. It summarises things I had to learn the hard way while developing my file manager, fman.
Since the original creation of this Wiki, I have open sourced my solutions to much of the issues below in one cohesive framework. It saves you literally months of development work. Check it out!
Don't use the latest and greatest as Qt has a reputation for having unstable .0 releases. For instance, at the time of this writing the most recent version of Qt is 5.9.0 but I'm using 5.6.2 because it has fewer bugs and is more stable.
I'm not a lawyer so take this with a grain of salt. Qt is licensed under the LGPL which lets you use it as a library. PyQt on the other hand is licensed under the GPL. If you are developing a commercial app, you thus need to purchase a commercial license for PyQt, but can use Qt (without having to pay) under the LGPL. My PyQt license costs £350 - per year. It was not clear to me from PyQt's purchasing page that you have to pay every year. Oh well.
I develop fman on a 2017 Dell XPS running Ubuntu 16.04. To build and test for the other OSs, I use virtual machines and Docker images. I have a Windows 7 VM and a macOS VM. When I release a new version, I first build in an Arch Docker Image. If all is well there, I release on a Ubuntu 12 Docker image. Then, I launch the Win 7 VM and kick off the release there. Finally, I usually build in the macOS VM. You can see a video of this entire process here.
Hint for Linux: Build your app on the earliest version of the distro you wish to support. That's why I'm using Ubuntu 12 and not (eg.) 16. The reason is that apps built on 12 are likely to work on 16, but not the other way around.
There are several frameworks for turning Python code into standalone applications that you can distribute to your users. The best option I have found for cross-platform PyQt applications is PyInstaller. I highly recommend you use it. It supports PyQt out of the box, works well across platforms and is actively maintained.
Other options:
- bbfreeze does not support Python 3 and is unmaintained.
- py2app is "not moving forward" because the author lacks the time.
- cx_Freeze has long periods without updates.
- py2exe is Windows-only and does not support Python >= 3.5.
- pyqtdeploy involves a Qt-based build process. Its GUI helper crashed when I tried to set up the (comprehensive) configuration.
There is no single good cross-platform technology for automatic updates. If you want your app to be able to auto-update itself, you need to pick a different technology for each OS. There is one library called Esky for auto-updating Python applications across OSs. But it doesn't work well and is unmaintained. I recommend:
- Sparkle on Mac. Useful snippet for interfacing with it from Python here.
- Google Omaha on Windows
- fpm for creating packages for the update managers of the various Linux distributions. For instance, you can use it to create a .deb file for Debian/Ubuntu, or .pkg.tar.xz for Arch Linux.
Most OSs require application binaries to be code signed to verify that they were not tampered with. For instance, on Windows 10, your users will get a message similar to the following if you don't sign your app:
Windows: The cheapest option seem to be the Class 2 certificates from StartSSL. They give you a .pfx
file. You then basically run Windows' signtool.exe
with this .pfx
file for each of the executable files in your application. You can find a Python snippet for performing the necessary steps here.
Mac: You get the certificate from Apple, by joining their Developer program. It's EUR 99 per year. You then use this command to sign your .app
/ .dmg
files:
codesign --deep --verbose -s "Developer ID Application: Michael Herrmann" target/fman.app
codesign --verbose -s "Developer ID Application: Michael Herrmann" target/fman.dmg
Linux: You normally use a GPG key to sign your apps.
When working with (Py)Qt for a while, it's not unlikely you'll want to read its source code to figure out how something is implemented (or why it isn't working as you expect). The easiest way to do this is to download the source release of Qt, extract it and then open the entire folder with Sublime Text (in fman you can do this by pressing F4 on the folder with the sources). Then, you can use Sublime Text's Ctrl/Cmd+P
to very quickly jump to the definition of a class. For instance, to open the source code for QLineEdit, type qlineedit.cpp
into Sublime Text.
Sponsored by fman, PyQt-based file manager for power users.