In this article, we will discuss several (better) alternatives to the popular Pyinstaller library in Python.
Python is a popular programming language widely used for creating a variety of applications, from web scraping to machine learning. One of the challenges of distributing Python applications is that they require a Python interpreter to be installed on the target system. To this day, there remains no “native” or “built-in” way of distributing Python applications, hence we need to resort to other libraries.
One such library is Pyinstaller.
However, Pyinstaller is not ideal for all situations and there are other alternatives out there, which we will introduce in this article and compare them to pyinstaller.
The first library that I want to discuss is cx_Freeze, because it is quite similar to how Pyinstaller works. Both cx_Freeze and Pyinstaller create standalone executable by bundling a copy of your Python environment into the newly created EXE. This process is called “freezing”.
This ensures that no matter where the EXE goes, the correct Python version and libraries that you installed will always be available to it.
So how is cx_Freeze any different from Pyinstaller?
- Faster load times than pyinstaller (Generally loads about twice as fast). By “load time” we mean the amount of time taken for the application to begin when the exe is clicked.
- Requires a little more configuration than Pyinstaller. Usually does not work “out-of-the-box” and requires some libraries to be manually included. Nothing too complicated, just need to add in a few extra options when compiling.
- Generates EXE’s of a larger size than pyinstaller. Around a 50% larger size was observed in the presence of a virtual environment.
- Compiles a bit slower than pyinstaller.
Verdict (cx_Freeze vs Pyinstaller)
cx_Freeze only has one advantage over pyinstaller, but it is a very important one. Most of the cx_Freeze disadvantages are things that will not hurt user experience (when using the application). Only the size disadvantage could be a problem for users with slow internet speeds or limited space.
Load time on pyinstaller is quite slow, and is probably the main reason why people look for alternatives. cx_Freeze has a very reasonable load time, hence why it is a popular choice.
If you are interested in giving cx_Freeze a shot, here is a link to our setup guide and tutorial on using cx_Freeze.
Nuitka is a Python compiler that converts Python code into a standalone binary executable, which can be used to improve performance and make distributing Python applications easier.
It is fully compatible with the Python language, and works by first compiling the Python code to a binary format, and then using a C compiler to convert it to machine code.
As you can see, this is rather different from how Pyinstaller works.
- Improves the performance of your application (since it’s no longer Python code, rather it is compiled machine code which executes faster).
- Fast load times. Nuitka has some of the best load times I’ve seen on any .py to .exe converter. It loads about 2 – 3 times faster than pyinstaller on the applications I have tested it on. This will likely vary based of the number and type of libraries you are importing.
- More “trust-worthy” than pyinstaller applications due to the compilation process. There have been occasions on which pyinstaller applications have been blocked by the Windows firewall (or something equivalent).
- Produces more secure applications (which are harder to decompile). This gives your source code more protection.
- Long compile times. When compiling code with many extra libraries (which are not already part of the Python Standard Library), Nuitka needs alot of time to convert and compile the code. This can easily take an hour if you have some big libraries like Matplotlib, Numpy, and SciPy.
- Larger EXE size. Nuitka generally produces a folder which about twice the size of a pyinstaller application. Nuitka has another mode called “onefile”, on which certain optimizations can be applied to reduce the file size. This can bring it pretty close to pyinstaller in terms of size (in onefile mode).
Verdict (Nuitka vs Pyinstaller)
Nuitka has several advantages over Pyinstaller. Better performance, faster load times, and is (generally) more trust-worthy and secure. These are some very good reasons to be using Nuitka over pyinstaller.
But, if the larger EXE size is a big problem then you might want to use either cx_Freeze or Pyinstaller. Because Nuitka (generally) produces EXE’s with a size larger than both cx_Freeze of Pyinstaller.
The long compile time is also something that may put you off. Its up-to you to decide whether the benefits are worth it or not. If you are interested in trying Nuitka, here is a link to our setup guide and tutorial on using Nuitka.
Other alternatives to Pyinstaller
There are even more alternatives out there. Some of which I have not have the chance to work with, and some which I do not consider worth mentioning (since we are only discussing “better” alternatives to Pyinstaller).
This marks the end of the cx_Freeze vs Pyinstaller comparison. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the tutorial content can be asked in the comments section below.