Create exe from Python code
1. Auto-py-to-exe
I will introduce a PyInstaller wrapper tool with GUI that I use for creating an executable file from smaller Python applications or scripts.
* Issue: I have an algorithm that is for a specific role. This algorithm is implemented in Python and works online, embedded in a Django web application. The issue is that the algorithm should run offline as a desktop application.
2. Creating exe from a main.py
How to start:
-
Create a folder then set an environment using venv:
python -m venv .venv.venv\scripts\activate -
Install Auto-py-to-exe & Pyinstaller
pip install auto-py-to-exe pyinstaller -
Copy the
requirements.txtfrom the application’s folder. -
Update with auto-py-to-exe and install the dependencies
pip freeze > requirements.txtpip install -r requirements.txt -
Run Auto-py-to-exe
auto-py-to-exe
Use the GUI:
- Add Script Location ( browse for a script [ main.py ] )
- Select One Directory
- Select Console Based (I don’t use windows/forms/panels in this case)
- Add Icon if you have one
- Additional Files
- Add the folders/files that are dependent on the application/project.
- After the compilation you should delete the source code and other copyright content. The .pyc (compiled Python) files will be generated for the desktop application after execution.
- You can set the project name & contents place: Advanced/General Options/ –name –contents-directory
Software info, rights
Advanced/Windows specific options/ –version-file
version.txt
# UTF-8
VSVersionInfo(
ffi=FixedFileInfo(
filevers=(1,0,0,0),
prodvers=(1,0,0,0),
mask=0x3f,
flags=0x0,
OS=0x4,
fileType=0x1,
subtype=0x0,
date=(0,0)
),
kids=[
StringFileInfo(
[
StringTable(
'040904B0',
[StringStruct('CompanyName', 'Your Name'),
StringStruct('FileDescription', 'What is it ...'),
StringStruct('FileVersion', '1.0.0.0'),
StringStruct('InternalName', 'my_app'),
StringStruct('LegalCopyright', 'Firstname Lastname Copyright (C) 2025'),
StringStruct('OriginalFilename', 'my_app.exe'),
StringStruct('ProductName', 'My_App'),
StringStruct('ProductVersion', '1.0.0.0')])
]),
VarFileInfo([VarStruct('Translation', [1033, 1200])])
]
)
The last step
CONVERT .PY TO .EXE