PyQT5 and cx_Freeze Windows™ target tips

  |   Source

One of my preferred benefits of Python is its portability and if coupled with good libraries such as PyQT5 the possibilities are endless.

Now imagine you created a new shiny desktop application and you want to distribute it, how can you package the app for easy installation?

Say hello to cx_Freeze

cx_Freeze is a tool that can create a standalone version of your application so you can easily distribute it and the end user don't have to:

  • download your source code

  • a python interpreter

  • setup pip or easy_install, libraries and so on

Another nice feature of cx_Freeze is that it can create an installer for many different operating systems giving your application a more "professional" look.

I strongly suggest giving it a try; using one of the sample setup scripts should be enough to get started.

Some minor issues

A simple application which only depends on pure python packages usually will not give you any headaches but if you have dependencies like PyQT5 a bit of attention is required. In my case not all the required DLL were included in the installer package and that generated a strange error message that was very hard to debug but thanks to sites like StackOverflow I've found a nice fix for it. It is worth noting that linked solution is not (always?) enough but there is a quick solution (at least in my case): add the file libegl.dll to the "include_files" cx_Freeze building options.

How to test your shiny new installer

In order to test your installer and be sure that all the DLLs are incuded and your application is not "cheating" on you using system DLLs I suggest to create a clean windows installation inside a virtual machine; this way you can test your installer in a real case scenario and fix your build scripts accordingly.

Comments powered by Disqus