PyBuild
Compile Python into standalone .exe. No Python needed on target machines.
Features
- Portable mode — bundles Python runtime into a folder, double-click to run
- Single-file mode — one
.exewith everything embedded (Python + stdlib + deps + assets) - Full stdlib collection — collects the entire standard library, zero missing-module errors
- Recursive dependency tracing — auto-discovers transitive third-party dependencies (A → B → C)
- Source protection —
.pycompiled to.pyc, local variable obfuscation, ZIP encryption (SHA-256 stream cipher), anti-debug (IsDebuggerPresent) - Auto asset detection — AST-based scanning for file references in string literals,
os.path.join(),Path(), f-strings - Interactive mode — drag-and-drop or type file paths
pybuild local— pack PyBuild itself into any directory for portable use- Config-driven builds —
pybuild.jsonsupports multiple build targets with per-build settings
Install
pip install pybuild-exe
Requires Python 3.10+ on Windows. Uses the built-in C# compiler (csc.exe) for launcher PE generation.
Quick Start
pybuild Main.py # portable mode (default, creates Main/Main.exe)
pybuild Main.py --single # single-file Main.exe
pybuild Main.py -o Game --single # single-file Game.exe
pybuild --config # build all targets from pybuild.json
pybuild --config builds.json # build from specified config file
pybuild local # pack PyBuild itself into current directory
Run pybuild with no arguments to enter interactive mode.
CLI Reference
| Command | Description |
|---|---|
pybuild Main.py |
Pack Main.py in portable mode (default) |
pybuild Main.py --single |
Pack Main.py into a single .exe |
pybuild Main.py -o Game |
Set output name to Game |
pybuild Main.py --outpath D:/output |
Set output directory |
pybuild Main.py --icon app.ico |
Embed icon into .exe |
pybuild Main.py --console |
Show console window (hidden by default) |
pybuild --config |
Build from pybuild.json (auto-find) |
pybuild --config builds.json |
Build from specified config |
pybuild local |
Pack PyBuild into current working directory |
pybuild --new |
View changelog |
Config File (pybuild.json)
{
"version": "1.0.0",
"product_name": "MyApp",
"company": "MyCompany",
"description": "My Application",
"builds": [
{
"entry": "main.py",
"output": "MyApp",
"outpath": "D:/release",
"single": true,
"console": false,
"icon": "assets/app.ico",
"assets": ["images", "sounds", "config.json"]
},
{
"entry": "tools/helper.py",
"output": "HelperTool",
"single": false,
"console": true
}
]
}
Config Fields
Top-level (version info, embedded into .exe properties):
| Field | Description |
|---|---|
version |
Version string (e.g. "1.0.0") |
product_name |
Product name, used as output exe name if set |
company |
Company name |
description |
File description |
Per-build:
| Field | Description |
|---|---|
entry |
Entry script path (relative to config file) |
output |
Output exe/folder name (default: entry script name) |
outpath |
Output directory (default: entry script directory) |
single |
true = single-file .exe, false = portable folder (default: false) |
console |
true = show console, false = hide (default: false) |
icon |
Path to .ico file (non-.ico images auto-converted via PIL) |
assets |
List of asset directories and/or files to include |
How It Works
- Collect — scans entry script imports recursively, finds all project
.pyfiles, third-party packages (with transitive deps), and the full standard library - Compile — all
.pyfiles compiled to.pycviacompile(optimize=2), with symbol obfuscation for project source - Encrypt — single-file mode encrypts the ZIP payload with a SHA-256 stream cipher, key embedded in the C# launcher
- Bundle — portable mode copies everything into a folder; single-file mode concatenates PE + encrypted ZIP + config footer
New in 1.15.0
pybuild localcommand — pack PyBuild into any directory for portable use withoutpip install- Full stdlib collection — replaced fragile AST import tracing with complete stdlib walk, eliminating all
No module named Xerrors - Recursive dependency tracing — third-party packages are scanned for their own imports, transitive deps auto-collected
- Self-pack fixes — PyBuild-exe.exe can now correctly build other projects via drag-and-drop (fixed
_pthisolation,find_specfallback, bootstrap naming collision) - Performance — cold-start extraction ~1.6s (was ~7s), cached start ~1s
- Asset support —
collect_assetsnow accepts individual files, not just directories
Contact
Email: 2674675526@qq.com
Bug reports, feature requests, and feedback are welcome.
License
MIT
Metadata
Release files for pybuild-exe 1.15.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pybuild_exe-1.15.3-py3-none-any.whl | Python 3 | none | any | Details |
Release files / pybuild_exe-1.15.3-py3-none-any.whl
| Download URL | pybuild_exe-1.15.3-py3-none-any.whl |
|---|---|
| Size | 82.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e360f6b03c70ea1da11b0d0315b559b44f3ec49499b5365a00c11cce00224d4d
|
|
BLAKE2b-256 checksum How to use checksums |
f52ee2ecbfd9d1ad44c2354c8a90cb71b897cff421fca585c456881df8a1e5b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|