Why convert?

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.

You can download the sample files from GitHub.

The script we are going to pack is quite simple, it merely displays text from the external file hello.txt (we will embed it in the final exe):

import sys
import codecs

def main():
    f = codecs.open('hello.txt', encoding='utf-8')
    for line in f:
        print repr(line)

if __name__ == "__main__":
    main()
			

Prepare project in BoxedApp Packer

First, download Python runtime and install it.

Important! Runtime files' bitness: 32-bit vs 64-bit.

Download the 32-bit version of the runtime to ensure the final exe runs well in both 32-bit and 64-bit Windows.

With the 64-bit runtime files, a 64-bit executable will be produced. It won't run in the 32-bit Windows.

At the same time, if you use the 32-bit runtime files, a 32-bit executable will be produced, which can run in both 32-bit and 64-bit Windows.

Then download BoxedApp Packer, launch it.

To execute the Python code, type:

> python.exe main.py
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:
<BoxedAppVar:OldCmdLine> "<ExeDir>\main.py"
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.

Screenshots

1. Select python.exe
Select python.exe
2. Set output name
Set output name
3. Override command line
Override command line
4. Import directories
Import directories
5. Add files
Add files
6. Build and run. It works!
Packed python application

Download

Both sources and BoxedApp Packer project are available on GitHub.