Pythub
Pythub 是一个开源的基于 Python 的 Python 应用打包工具: 一条命令,把应用打包成免装 Python、可直接运行的产物——在一个平台上即可交叉打包 Windows / macOS / Linux 多平台、多版本 Python、多架构的自包含产物,并支持打包/发布 PyPI 包。
版权归属开源组织 CROGRAM · https://crogram.org
特性
- 跨平台交叉打包:在 Mac 上打包 Windows
.exe(自研引导器)/.exe.zip、Linuxtar.gz/.run/AppImage;在 Windows 上打包 macOStar.gz等 - 多 Python 版本:3.10 / 3.11 / 3.12(产物内嵌目标版本解释器,目标机器免装 Python)
- 运行时自动瘦身:官方 stripped 运行时 + 剪除 test/idlelib/pip/调试符号等冗余,Windows
.exe.zip体积降低约 76%(55M→13M) - 多架构:x86_64 / aarch64(含 Apple Silicon、Windows ARM64)
- 平台专属格式:
.app/.dmg/.pkg(macOS)、AppImage /tar.gz/ 单文件自解压.run/ 原生单文件.nexe(Linux)、.exe.zip/ 单文件.exe(Windows,自研 C 引导器 + 自研压缩归档 + stdlib zip 化,实测 12.3MB)、单文件pyz;macOS/Linux 的.nexe为原生单文件可执行(同一套自研 C 引导器与归档格式,仅本机平台生成) - 智能组件选择:自动分析 import,按目标平台下载对应平台的第三方组件(Mac 打包只带 Mac 组件,Windows 打包只带 Windows 组件)
- 双引擎:默认
zipapp引擎(自研、支持交叉);可选pyinstaller引擎生成本机真单文件二进制 - 命令行 + GUI:
pythub(argparse)与pythub-gui(tkinter),组件全部为 Python 内置或自研实现 - PyPI 生态:
pythub pypa build打 sdist/wheel,pythub pypa publish直接发布到 PyPI(stdlib 实现);Pythub 自身亦可发布到 PyPI(pip install crogram-pythub)
安装
# 生产模式安装,本地仓库
pip install .
# 克隆源码
git clone https://github.com/crogram/pythub.git
cd pythub
# 开发模式安装(修改代码立即生效)
pip install -e .
# 发布后:
pip install crogram-pythub
服务管理
快速开始
# 1. 创建示例工程
pythub init
# 2. 分析依赖
pythub analyze hello_app
# 3. 交叉打包:在任意平台打包所有平台产物(默认 Python 3.12)
pythub build hello_app -p all
# 指定平台/格式/Python 版本/架构
pythub build hello_app -p windows -f exe.zip --py 3.11
pythub build hello_app -p macos -f app --arch aarch64
pythub build hello_app -p linux -f appimage
pythub build hello_app -p linux -f run
# 本机生成真正的单文件二进制(需 pip install pyinstaller)
pythub build hello_app -p macos -f onefile --engine pyinstaller
# 4. 可视化界面
pythub gui
PYTHONPATH=src python3.11 -m pythub gui
打包为 PyPI 包并发布
pythub pypa build hello_app -o dist # 生成 sdist + wheel
pythub pypa publish dist/*.whl --repo pypi --token pypi-xxxx
GUI 的「发布 PyPI」页同样可选择 dist 中的文件直接上传。
产物格式矩阵
| 目标平台 | 格式 | 默认 | 交叉支持 |
|---|---|---|---|
| Windows | exe.zip / exe / dir / pyz |
exe.zip | ✅(.exe 单文件需构建机有 mingw-w64:brew install mingw-w64,自研 C 引导器交叉编译) |
| Linux | tar.gz / nexe / run / appimage / dir / pyz |
tar.gz | ✅(nexe 原生 ELF 单文件仅本机平台生成;.run 单文件自解压可执行,零依赖可交叉;AppImage 需构建机有 appimagetool,缺失时降级 .run) |
| macOS | app / dmg / pkg / tar.gz / nexe / dir / pyz |
app | nexe 原生 Mach-O 单文件(自研 C 引导器 + 归档)需在 macOS 上打包;其余可交叉 |
说明:Python 生态中真正的"交叉编译二进制"受解释器限制。Pythub 的 zipapp 引擎采用
自包含产物方案(内嵌 python-build-standalone 独立解释器 + zipapp + 平台启动器),
目标机器解压即可运行、无需安装 Python;需要真正单文件二进制时,在本机平台使用
--engine pyinstaller。
工程配置 pythub.toml
[app]
name = "hello-pythub"
entry = "main.py"
version = "0.1.0"
description = "示例应用"
author = "CROGRAM"
requirements = ["requests"] # 第三方依赖;也可用 requirements.txt
windowed = false # true: GUI 应用隐藏控制台黑框(exe 引导器 -mwindows;app/.app 同样生效)
项目结构
src/pythub/
├── cli.py # 命令行入口
├── gui.py # tkinter 可视化界面
├── config.py # pythub.toml / requirements 解析
├── analyzer.py # AST 依赖分析(标准库/第三方/发行包映射)
├── deps.py # 按目标平台下载 wheel(pip 交叉下载)
├── runtime.py # 嵌入式 Python 运行时下载与缓存
├── builder.py # 打包主流程(zipapp 引擎)
├── formats.py # .app/.dmg/.pkg/AppImage/.exe.zip/.run/.exe 格式实现
├── exe_archive.py # 自研 Windows 单文件 .exe 打包器(zlib 压缩归档 + stdlib zip 化 + 引导器交叉编译缓存)
├── bootloader/
│ └── bootex.c # 自研单文件引导器源码(Windows PE / POSIX 双分支)
├── native_builder.py # PyInstaller 引擎(本机真二进制)
└── pypa.py # sdist/wheel 构建 + PyPI 上传
examples/hello_app/ # 示例工程(测试与验证用)
docs/ # 原始需求与需求梳理清单
License
MIT © CROGRAM
Metadata
Release files for crogram-pythub 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crogram_pythub-0.1.0.tar.gz | 71.1 kB | Without provenance | Details for crogram_pythub-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| crogram_pythub-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for crogram_pythub-0.1.0-py3-none-any.whl |
Total release size: 152.5 kB
Release files / crogram_pythub-0.1.0.tar.gz
| Download URL | crogram_pythub-0.1.0.tar.gz |
|---|---|
| Size | 71.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1eebfd24cdedcb2d96a2c588a3ff80e1df062a479b8fed75006a950660bdaea
|
|
BLAKE2b-256 checksum How to use checksums |
7ce7a99658ee56c640bc5c9421c5e069125d2ef43362de253cd8e4a6a2b61c3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|
Release files / crogram_pythub-0.1.0-py3-none-any.whl
| Download URL | crogram_pythub-0.1.0-py3-none-any.whl |
|---|---|
| Size | 81.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b431836aa4b9d3e83d81da85a54b5d669af44efa406ddc16f36cc62531321cd4
|
|
BLAKE2b-256 checksum How to use checksums |
951e98fef17d88daf8396e4a4686b3b91dea1a0fc1fe7270844b0136c2817e73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|
Security for crogram-pythub 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.