HowTo compile Python apps into a standalone app

Sometimes, it makes sense to make an application independent from having Python itself installed.

While tools like PyInstaller allow to build a standalone app from a Python project, it is still interpreted Python it runs. It does that by bundling the Python interpreter, all required dependencies as well as the project’s Python code into a single file. This file also includes a bootstrap mechanism which allows to start the Python interpreter to run the code.

This is great, but if there is also a performance improvement wanted, we don’t get away without compiling, right? This is where Nuitka comes into play. It is able to build a standalone binary, including the Python interpreter as well, along with bootstrap code to run it. But in addition, it is able to compile the project’s Python code into C code, which is then compiled into machine code. This code is still using the Python interpreter, but it does this through Python’s C API. Along with the compiled code, it can make a compute-intense app significantly faster.