Monday, 24 November 2014

Python packaging/freezing experiment with Nuitka and cx_Freeze

A while ago I made the decision to move to Ubuntu Linux at the PC that I use at the office as well as the computer that I use at home. To me a Linux environment is more appealing. Although I've used Windows for a very long time I'm very attracted to the freedom that I have in Linux and that's why I started to clean up my Windows devices to be able to make a smooth transition to the new operating system. Recently I started with finishing some unfinished projects. Some of them can only run or Windows or take too much time to set up within the new Linux environment. So the easiest way was to finish them. One of this projects was a small experiment with Python freezing tools to find out how well Nuitka was able to freeze packages.

Freezing is an interesting process which allows you to distribute your Python based apps to other users. What you basically do during a freezing process is grabbing all the Python code and the related dependencies and you place them in a single place together with a Python interpreter. In this way the users can run your app.

During my experiment I played with two packages which allow you to freeze a Python project: Nuitka and cx_Freeze. The last one is a very well known tool to me. cx_Freeze allowed me to package a production grade app without problems. Although the configuration can be a little bit frustrating because the documentation lacks some examples it is a very reliable package. I would advice it to everybody who wants to freeze Python 3.x apps.

The second freezing tool is Nuitka. It's a Python compiler which compiles every construct of Python to C++. The parts that can't be compiled to C++ are executed by the default Python interpreter (libpython). This is done in a very compatible manner. This means it speeds up some parts of your application without breaking it. A nice addition to the compiler is that it can create standalone packages just like cx_Freeze and similar packages like py2exe and Pyinstaller.

screenshot example appsDuring my experiment I've frozen 2 small “Hello World!” applications: One CLI application and one GUI application based on Qt (PySide).
During the experiment I've found out that both packages are able to freeze the applications without problems. The main advantage of Nuitka was that it created a (signable) file without a library zip file which makes it less easy for people to decompile the application. It seems like Nuitka is promising because of it's performance gains and the highly compatible standalone feature. However there is still work to be done and the author needs some help in this.

At my project GitHub page you can check out the two examples. Hopefully it can help you out if you want to freeze one of your Python applications using one of these tools. I've tested it on a Windows 8.1 machine, but I'm quite sure that it will also work on other platforms.

Because I want to focus more on web development I'll not continue actively with experimenting with freezing tools. So this project is finished for now. However I'll watch the freezing projects because there are quite some interesting things going on like the updater package for Pyinstaller and I think projects like these can become a very nice foundation for upcoming (desktop) apps written in Python.


  1. Thanks for sharing amazing information about python .Gain the knowledge and hands-on experience in python Online Training

  2. Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You !

    Digital Marketing Training in Chennai

    Digital Marketing Course in Chennai