The Pain of PyInstaller: Convenient but Insecure
I once wrote an automation tool for sending reports to clients. Everything ran perfectly until I discovered that the source code, including database information, could be easily extracted. If you’re using PyInstaller, be careful.
In essence, PyInstaller is like a box containing compressed source code along with a Python interpreter. Using pyinstxtractor, even someone who doesn’t know how to code can retrieve your entire logic in less than 30 seconds. Additionally, having to decompress files on startup makes the application heavy and significantly slower.
Why is Python Source Code So Easy to ‘Steal’?
Python is an interpreted language. When you run a script, it’s converted into bytecode (.pyc files). However, the structure of bytecode is very close to human-readable language. Current decompilation tools can recover up to 95% of the original code from these files.
If your project contains proprietary algorithms or important API keys, standard packaging is a major risk. You need a solution that completely changes the structure of the executable, rather than just hiding it superficially.
Nuitka – The Secret Weapon for Professionals
Nuitka doesn’t follow the traditional packaging path. It compiles your entire Python script into C++. Then, the system uses powerful compilers like GCC or MSVC to create a pure binary file.
The result is an executable that runs directly on hardware. Decompiling from a C++ binary back to Python code is nearly impossible. According to real-world tests, heavy computational tasks compiled via Nuitka can be 10% to 30% faster than running with a standard interpreter.
1. Setting Up the Compilation Environment
Since Nuitka converts code to C++, your machine must have a compatible compiler. Don’t worry, this process only takes about 5 minutes.
- Windows: Install Visual Studio Community. During installation, check the “Desktop development with C++” option.
- Linux: Everything is simpler with the command:
sudo apt install build-essential python3-dev.
Finally, install the latest version of Nuitka:
pip install -U nuitka
2. Compiling Your First Project
Test it with your app_chinh.py file. Instead of using complex commands, start with this optimized syntax:
python -m nuitka --standalone --onefile --show-progress app_chinh.py
Quick explanation of the parameters:
--standalone: Automatically bundles all dependencies to run on machines without Python installed.--onefile: Outputs a single, compact.exefile.--show-progress: Helps you monitor every compilation step in real-time.
3. Real-world Tips to Reduce File Size
Many complain that Nuitka build files are too heavy, sometimes reaching 150MB for a simple script. Here is how I handle this issue:
Enable Smart Plugins: Nuitka needs to know which libraries you are using to optimize. If you use graphics or data libraries, add the corresponding flag:
python -m nuitka --standalone --enable-plugin=pyside6 script.py
Block ‘Junk’ Modules: Sometimes the system pulls in heavy libraries like tkinter even if you don’t use them. Use --nofollow-import-to=tkinter to remove them immediately.
Compress with UPX: If UPX is available on your machine, Nuitka will automatically compress the binary. This helps reduce the executable size to about 1/3 of the original.
Comparison Table: Is Nuitka Really Worth It?
| Feature | PyInstaller | Nuitka |
|---|---|---|
| Core Mechanism | Bundling (Compression) | Compiling (C++) |
| Security | Weak (Code easily exposed) | Very Strong (Binary encryption) |
| Startup Performance | Slow (due to decompression) | Very Fast (direct execution) |
| Build Time | Fast (seconds) | Long (minutes) |
Advice for Real-world Project Deployment
Don’t rush to compile while the code still has bugs. The most professional workflow I apply includes 3 steps:
- Finalize the code and debug thoroughly in a virtual environment (Virtualenv).
- Clean up the virtual environment, installing only necessary libraries to avoid bloated build files.
- Use a high-performance computer for compilation, as the C++ compile process consumes significant CPU.
If you are developing commercial tools, MMO tools, or high-security software, Nuitka is a worthy investment. Although the build time is longer, the peace of mind and professionalism it provides are on a completely different level.

