How to convert a Python application into a self-sufficient single exe file?
Imagine you have an application written in Python and decided to distribute it to your clients. But how will you do that? Just zip all the files to share with users? Ask them to install Python runtime?
Moreover, anyone could modify the scripts, extract the resources, etc.
But what if you could combine Python runtime and the application files into a single executable file? In this case, the runtime installation would not be required, and the application's sources would be hidden.
In this tutorial, I will show you how to achieve this with BoxedApp Packer.
But, of course, we don't want to ask our users to pass additional arguments, so we have to embed this command line in the packed exe. That's easy: check "Override command line" and enter there:
That means that the packed exe will run as if main.py was really passed!
We also need to pack python.exe that interprets python scripts. So, select it as the input exe. Also, we need to add some extra files: folders DLLs, and Lib. In fact, you can remove the files that are not required by your application, although it's better to include everything. So, let's import those folders.
Additionally, python27.dll is required; find it in the System32 directory (or in SysWow64 on 64-bit Windows) and add it to Application Directory.
Of course, we should also add main.py (the script file) and hello.txt (the script reads this file).
Now we are ready to build and run it. See the screenshots below.
1. Select python.exe
2. Set output name
3. Override command line
4. Import directories
5. Add files
6. Build and run. It works!
Both sources and BoxedApp Packer project are available on GitHub.
BoxedApp is a virtualization library, an executable packer, and a developer API to create custom packers.