In this article, we will compare two popular Python libraries used for creating standalone executables, Nuitka and Pyinstaller. This “Nuitka vs Pyinstaller” article will directly compare both libraries on things like “load time”, “performance”, “space”, etc.
By the end of this article, we you will understand the benefits of each library, and which one you ought to be using.
What is Nuitka?
Nuitka is a Python compiler that converts Python code into a binary executable.
It is fully compatible with the Python language and can significantly improve the performance of Python code. It does this by compiling the Python code to a binary format, and then compiling it to machine code using a C compiler.
Nuitka can also create standalone executables that do not require a Python interpreter to be installed on the target system, making it easier to distribute Python applications.
Advantages of using Nuitka
Before a direct comparison with Pyinstaller, we will list down the general advantages of using Nuitka.
Improved performance: Nuitka can significantly improve the performance of Python code by compiling it to a binary format that can be executed more efficiently than interpreted code. This can result in faster execution times and better resource utilization.
This point in particular sets Nuitka apart from other converters, as the others do not improve performance.
Standalone executables: Nuitka can create standalone executables that do not require a Python interpreter to be installed on the target system. This makes it easier to distribute Python applications to users who may not have Python installed on their own systems.
Easy to use: Nuitka has a simple command-line interface and can be easily integrated into existing Python projects. No need to setup additional setup files, or create an entirely new project.
Cross-platform support: Nuitka can create executables for multiple platforms, including Windows, Linux, and macOS.
Improved security: Compiling Python code to a binary format can make it more difficult for attackers to reverse engineer or modify the code. This can improve the security of Python applications that are distributed as standalone executables. The commercial version of Nuitka also offers additional security and source code protection for serious users.
Firewall resistant: Nuitka applications may be less likely to be detected by anti-virus and firewall software, since it is in a compiled form. However, modern anti-virus systems and firewalls are quite advanced. If your script is malicious or perform some suspicious actions, there is a good chance it will flag.
In comparison, there have been reports of pyinstaller applications being flagged the firewall (windows) even when they were not malicious.
What is Pyinstaller?
PyInstaller is a tool for packaging Python applications as standalone executables. It converts Python code into a single executable file that can be run on systems without a Python interpreter installed.
PyInstaller can also be used to customize the way executables are built, including the ability to include or exclude specific files or modules easily (using a spec file).
Advantages of using Pyinstaller
Easy to use: Pyinstaller has a simple command-line interface and can be easily integrated into existing Python projects. No need to setup additional setup files, or create an entirely new project.
The compilation times are pretty fast as well, and the resulting EXE size is within acceptable limits (can be optimized further).
Cross-platform support: Pyinstaller can create executables for multiple platforms, including Windows, Linux, and macOS.
Improved security: By compiling the code to an executable, you can hide your source code. However, this can be reverse-engineered easily enough using tools. But it’s better than distributing your source-code as is.
Standalone executables: Nuitka can create standalone executables that do not require a Python interpreter to be installed on the target system. This makes it easier to distribute Python applications to users who may not have Python installed on their own systems.
Large community: Out of all libraries used for executable creation, Pyinstaller is probably the most well-known one. This also means it has a large number of online resources, videos and guides to follow.
You can easily find other people online posting about issues, and they solved them. This makes things alot easier and faster to solve when you run into any issues.
Pyinstaller vs Nuitka Comparison
Here is a direct comparison between the two libraries, summarizing the above points, adding a few extra ones, and including my own observations and personal benchmarks.
Pyinstaller | Nuitka | |
Performance | Pyinstaller works by bundling the Python interpreter in the Exe. Hence it has the same performance as regular Python code. | Nuitka performs faster than Pyinstaller, and is a great way to get a speed boost for a computationally heavy application. |
Size | Varies greatly based on libraries included and settings. For a general idea though: 1. Python (no libs): 20mb 2. Python + few libs: 100mb 3. Python + many/big libs: 300mb | Varies greatly based on libraries included and settings used. For a general idea though: 1. Python (no libs): 25mb 2. Python + few libs: 150mb 3. Python + many/big libs: 500mb Does not scale very well with the number of libraries added (especially when they are big). |
Cross-platform | All Major platforms (Windows, macOS, Linux, BSD, etc.) | All Major platforms (Windows, macOS, Linux, BSD, etc.) |
Loading time | Takes a long time to load, especially the one-file setting. About 5 – 10 seconds for most applications. | Loads much more quickly. About 2 – 5 seconds for most applications. |
Compile time | Compile time scales well with the number of libraries. Doesn’t take longer than 5 minutes on average. | Varies greatly based on the number of libraries. Can take a few mins, to a few hours (if using big libraries). |
Community | Pyinstaller has been around longer than Nuitka, is more commonly used and has more online resources. | Not many resources or guides on Nuitka. Its documentation is going to be your main resource. |
Optimizations | Pyinstaller can be optimized (size-wise) by using UPX or virtual environments to reduce bloat (extra libraries). | Nuitka can be optimized in various ways. 1. Cache to improve compile time greatly. 2. zstandard module to reduce size (onefile mode) 3. UPX packer to reduce EXE size. |
Pyinstaller vs Nuitka Conclusion?
Both are pretty solid options, and for about half of their use-cases there is little difference. Personally I would recommend Nuitka however, for the performance and load time improvement.
If you are looking for a (slightly) easier time though, Pyinstaller would be better. Faster compilation, better online support, etc.
Best to try out both, and then make a decision.
This marks the end of the Nuitka vs Pyinstaller comparison article. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the tutorial content can be asked in the comments section below.