Why to convert?

Imagine, you have an application written in Python and decided to distribute it to your clients. But how to do it? 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 to combine the Python runtime and the application files into one executable file? In this case the runtime installation is not required and application sources are hidden.

In this tutorial I will show you how to achieve it with BoxedApp Packer.

You can download the sample files from GitHub.

The script we are going to pack is quite simple, it shows text from the external file hello.txt (we will embed it into 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 a project in BoxedApp Packer

Firstly download Python runtime and install it.

Important: runtime files bitness: 32-bit vs 64-bit.

Download 32-bit version of the runtime to be sure the final exe runs well on both 32-bit and 64-bit Windows.

Using 64-bit runtime files, a 64-bit executable will be produced. It doesn't run on 32-bit Windows.

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

Then download BoxedApp Packer, launch it.

To execute a Python code you type:

> python.exe main.py
But, of course, we don't want to ask users to pass additional arguments. That's why we have to embed this command line into packed exe. It's easy: check "Override command line" and enter there:
<BoxedAppVar:OldCmdLine> "<ExeDir>\main.py"
It means that the packed exe runs as if main.py really passed!

We need to pack python.exe that interprets python scripts. So select it as input exe. Also we need to add additional files: folders DLLs and Lib. In fact you can remove files that are not required by your application, but firstly better to include everything. So let's import these folders.

Additionally, python27.dll is required, find it in System32 directory (or in SysWow64 on 64-bit Windows) and add to Application Directory.

Of course we also should add main.py (a script file) and hello.txt (the scripts reads this file).

Now we are ready to build it and run. See 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.