Metadata-Version: 2.4
Name: pybuild-exe
Version: 1.15.4
Summary: A Python-to-EXE compiler with smart import tracing, single-file output, and source code protection. Alternative to PyInstaller.
Author-email: Zachary_Hale <2674675526@qq.com>
License-Expression: MIT
Project-URL: Homepage, https://pypi.org/project/pybuild-exe/
Keywords: exe,packer,compiler,standalone,pyinstaller-alternative,python-to-exe,python-to-exe-compiler,single-file,source-protection,打包
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# 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 `.exe` with 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** — `.py` compiled 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.json` supports 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)

```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

1. **Collect** — scans entry script imports recursively, finds all project `.py` files, third-party packages (with transitive deps), and the full standard library
2. **Compile** — all `.py` files compiled to `.pyc` via `compile(optimize=2)`, with symbol obfuscation for project source
3. **Encrypt** — single-file mode encrypts the ZIP payload with a SHA-256 stream cipher, key embedded in the C# launcher
4. **Bundle** — portable mode copies everything into a folder; single-file mode concatenates PE + encrypted ZIP + config footer

## New in 1.15.0

- **`pybuild local`** command — pack PyBuild into any directory for portable use without `pip install`
- **Full stdlib collection** — replaced fragile AST import tracing with complete stdlib walk, eliminating all `No module named X` errors
- **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 `_pth` isolation, `find_spec` fallback, bootstrap naming collision)
- **Performance** — cold-start extraction ~1.6s (was ~7s), cached start ~1s
- **Asset support** — `collect_assets` now accepts individual files, not just directories

## Contact

Email: 2674675526@qq.com

Bug reports, feature requests, and feedback are welcome.

## License

MIT
