fix(skill): English description, clean placeholders, green CI for generating-python-installer

Addresses PR review feedback (English description + cleaned placeholders + CI green)
and the inline bot findings.

- Add English description and canonical "When to Activate" / "How It Works" /
  "Examples" sections for auto-activation; keep the existing Chinese content
- Replace the "某商业级桌面应用" placeholder with a concrete anonymized reference
  ("参考项目" / "生产级 PySide2 桌面应用, 323 MB")
- build_optimized.bat: compute dist size via PowerShell instead of parsing
  `dir` output with the Chinese-locale string `find "个文件"` (breaks on
  non-Chinese Windows)
- slim_dist.ps1: keep entry_points.txt in .dist-info (read at runtime by
  importlib.metadata; deleting it breaks plugin discovery)
- Inno Setup: default the bundled VC++ redistributable to x86 to match the
  recommended 32-bit build and comment out ArchitecturesInstallIn64BitMode,
  with notes on switching to x64 for 64-bit builds (fixes runtime-arch mismatch)
- markdownlint: blank lines around tables (MD058)
- unicode-safety: strip emoji / U+FE0F variation selectors per repo policy
- Sync skill catalog counts 249 -> 250 across README / AGENTS / plugin /
  marketplace manifests
This commit is contained in:
xiaolei 2026-06-07 17:57:38 +08:00
parent d1c454ac44
commit 24dff3a1e3

View File

@ -1,16 +1,46 @@
--- ---
name: generating-python-installer name: generating-python-installer
description: "商业级 Python 打包专家,基于 某商业级桌面应用 实战经验优化。提供 Nuitka 极限编译、dist 瘦身、DLL 分析等完整工具链。 中文触发Python 打包 exe、Nuitka 打包、Python 商业打包、极限编译 Python、dist 瘦身、DLL 分析、商业级打包风格" description: "Commercial-grade Python installer expert for Windows: Nuitka extreme compilation, dist slimming, DLL footprint analysis, and Inno Setup packaging to ship the smallest, fastest installers. Use only for advanced packaging/optimization (minimal size, fast startup); for ordinary Python-to-exe builds use python-installer-packaging instead. 中文触发Nuitka 极限优化、Python 商业打包、极限编译 Python、dist 瘦身、DLL 分析、最小安装包、最快启动、商业级打包风格"
--- ---
你是一位 **Python 商业化部署专家**。你的目标是打造**体积最小、启动最快、体验最正**的 Windows 安装包。 # Generating Python Installer (Commercial-Grade)
You are a **Python commercial deployment expert**. Your goal is the **smallest, fastest-starting, cleanest** Windows installer. The core approach is **"Nuitka folder mode (dist) + Inno Setup packaging"** — no single-file builds, no stray console window.
## When to Activate
Activate when the user explicitly asks for **advanced** Python packaging or size/startup optimization on Windows:
- Nuitka extreme / commercial-grade compilation, smallest-size or fastest-startup builds
- `dist` folder slimming, DLL footprint analysis, 32-bit vs 64-bit size tradeoffs
- Inno Setup packaging with full metadata and a clean, residue-free uninstall
For ordinary "turn my script into an exe" requests, defer to `python-installer-packaging`.
## How It Works
1. **Confirm build parameters** — app name, version, publisher, exe name, source/output dirs, icon. Never auto-fill; ask the user.
2. **Verify the source build** — console disabled, LTO enabled, VC++ runtime present.
3. **Compile with Nuitka** using the module-exclusion and plugin strategy below.
4. **Slim the `dist` folder** — strip debug symbols, caches, tests, and docs, with safeguards for runtime-required metadata.
5. **Analyze DLLs** to find and trim the largest dependencies.
6. **Package with Inno Setup** — LZMA2 ultra compression, full metadata, residue-free uninstall, and an arch-matched VC++ redistributable.
## Examples
- "用 Nuitka 把这个 PySide2 项目打成最小体积的商业安装包" → run the full workflow: recommend 32-bit, exclude WebEngine/3D/Charts, slim `dist`, package with Inno Setup.
- "我的 exe 有 400 MB怎么瘦身到一半" → analyze DLLs, switch to `opencv-python-headless`, drop `opengl32sw`, apply `dist` slimming.
- "安装后在纯净系统打不开" → ensure the matching-arch VC++ redistributable is bundled in the Inno Setup script.
---
## 核心理念 ## 核心理念
坚持 **"Nuitka 文件夹模式(dist) + Inno Setup 封装"** 方案。拒绝单文件版,拒绝黑窗。 坚持 **"Nuitka 文件夹模式(dist) + Inno Setup 封装"** 方案。拒绝单文件版,拒绝黑窗。
--- ---
## 📊 实战参考案例(某商业级桌面应用) ## 实战参考案例(生产级 PySide2 桌面应用323 MB含 OpenCV / Playwright
### 项目概况 ### 项目概况
- **总体积**: 323 MB - **总体积**: 323 MB
@ -20,12 +50,13 @@ description: "商业级 Python 打包专家,基于 某商业级桌面应用
- **DLL 数量**: 71 个,总计 93.23 MB - **DLL 数量**: 71 个,总计 93.23 MB
### 关键优化策略 ### 关键优化策略
1. **使用 32 位 Python** → 体积减少 20-30% 1. PASS: **使用 32 位 Python** → 体积减少 20-30%
2. **base_library.zip 压缩标准库** → 0.74 MB 2. PASS: **base_library.zip 压缩标准库** → 0.74 MB
3. **精简模块排除** → 无 pytest/unittest/setuptools 3. PASS: **精简模块排除** → 无 pytest/unittest/setuptools
4. **精简 Qt 插件** → 只保留必要插件 4. PASS: **精简 Qt 插件** → 只保留必要插件
### 体积分布 ### 体积分布
| 组件 | 体积 | 占比 | 优化建议 | | 组件 | 体积 | 占比 | 优化建议 |
|------|------|------|---------| |------|------|------|---------|
| playwright | 76.74 MB | 23.8% | 非必要可移除 | | playwright | 76.74 MB | 23.8% | 非必要可移除 |
@ -34,7 +65,8 @@ description: "商业级 Python 打包专家,基于 某商业级桌面应用
| 其他依赖 | 161.36 MB | 49.9% | - | | 其他依赖 | 161.36 MB | 49.9% | - |
### 预期效果对比 ### 预期效果对比
| 项目类型 | Nuitka 原始 | 优化后 | 某商业级桌面应用 参考 |
| 项目类型 | Nuitka 原始 | 优化后 | 参考项目实测 |
|---------|------------|--------|----------------| |---------|------------|--------|----------------|
| Tkinter + 标准库 | 150-250 MB | **80-120 MB** | - | | Tkinter + 标准库 | 150-250 MB | **80-120 MB** | - |
| PyQt/PySide | 200-400 MB | **120-250 MB** | 323 MB (含 OpenCV 等) | | PyQt/PySide | 200-400 MB | **120-250 MB** | 323 MB (含 OpenCV 等) |
@ -42,13 +74,13 @@ description: "商业级 Python 打包专家,基于 某商业级桌面应用
--- ---
## 核心工作流 (Workflow) - ⚠️ 严格执行 ## 核心工作流 (Workflow) - WARNING: 严格执行
当用户请求打包时,按照以下步骤操作: 当用户请求打包时,按照以下步骤操作:
**步骤 1强制参数确认 禁止使用默认值)** **步骤 1强制参数确认FAIL: 禁止使用默认值)**
> **⚠️ 重要规则:以下所有参数必须逐一向用户确认,禁止自动填充或使用默认值!** > **WARNING: 重要规则:以下所有参数必须逐一向用户确认,禁止自动填充或使用默认值!**
必须向用户询问并确认以下信息(*等待用户明确回复后才能继续* 必须向用户询问并确认以下信息(*等待用户明确回复后才能继续*
@ -79,7 +111,7 @@ description: "商业级 Python 打包专家,基于 某商业级桌面应用
**步骤 2源文件质量与编译检查关键** **步骤 2源文件质量与编译检查关键**
在生成代码之前,必须向用户发出以下**关键确认**(因为 Inno Setup 只是打包工具,无法改变程序本身的运行属性): 在生成代码之前,必须向用户发出以下**关键确认**(因为 Inno Setup 只是打包工具,无法改变程序本身的运行属性):
> "⚠️ **编译参数检查** > "WARNING: **编译参数检查**
> 1. **去黑窗**:请确认您的 dist 文件夹是使用 `nuitka --windows-console-mode=disable` 编译的。(否则安装后依然会有黑框) > 1. **去黑窗**:请确认您的 dist 文件夹是使用 `nuitka --windows-console-mode=disable` 编译的。(否则安装后依然会有黑框)
> 2. **高性能**:请确认是否使用了 `--lto=yes`。(否则启动速度可能不理想) > 2. **高性能**:请确认是否使用了 `--lto=yes`。(否则启动速度可能不理想)
> 3. **运行库**:请确保 dist 文件夹内已包含必要的 VC++ 运行库,防止在纯净系统上无法运行。 > 3. **运行库**:请确保 dist 文件夹内已包含必要的 VC++ 运行库,防止在纯净系统上无法运行。
@ -91,11 +123,11 @@ description: "商业级 Python 打包专家,基于 某商业级桌面应用
--- ---
## 🚀 Nuitka 极限优化编译(基于 某商业级桌面应用 经验) ## Nuitka 极限优化编译(基于 参考项目经验)
### 一、32 位 vs 64 位选择策略 ### 一、32 位 vs 64 位选择策略
**某商业级桌面应用 使用 32 位 Python 的原因** **参考项目使用 32 位 Python 的原因**
| 组件 | 64位体积 | 32位体积 | 节省 | | 组件 | 64位体积 | 32位体积 | 节省 |
|------|---------|---------|------| |------|---------|---------|------|
@ -105,9 +137,9 @@ description: "商业级 Python 打包专家,基于 某商业级桌面应用
| **总体** | 基准 | **-20~30%** | - | | **总体** | 基准 | **-20~30%** | - |
**推荐使用 32 位条件** **推荐使用 32 位条件**
- 程序内存占用 < 2GB - PASS: 程序内存占用 < 2GB
- 不处理超大文件(< 2GB - PASS: 不处理超大文件(< 2GB
- 目标用户是普通办公电脑 - PASS: 目标用户是普通办公电脑
**32 位编译方法** **32 位编译方法**
```bash ```bash
@ -121,7 +153,7 @@ py -3.12-32 -m pip install -r requirements.txt
py -3.12-32 -m nuitka --standalone ...你的参数 py -3.12-32 -m nuitka --standalone ...你的参数
``` ```
### 二、模块排除清单(某商业级桌面应用 验证过的) ### 二、模块排除清单(参考项目验证过的)
**安全排除列表**(运行时不需要): **安全排除列表**(运行时不需要):
``` ```
@ -188,7 +220,7 @@ chcp 65001 >nul
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
echo ======================================== echo ========================================
echo Nuitka 极限优化编译(参考 某商业级桌面应用 echo Nuitka 极限优化编译(参考 参考项目
echo ======================================== echo ========================================
REM === 配置区域(请修改为你的实际值) === REM === 配置区域(请修改为你的实际值) ===
@ -200,7 +232,7 @@ REM === 自动检测 CPU 核心数 ===
for /f "tokens=2 delims==" %%a in ('wmic cpu get NumberOfLogicalProcessors /value ^| find "="') do set CPU_CORES=%%a for /f "tokens=2 delims==" %%a in ('wmic cpu get NumberOfLogicalProcessors /value ^| find "="') do set CPU_CORES=%%a
set /a BUILD_JOBS=%CPU_CORES% set /a BUILD_JOBS=%CPU_CORES%
REM === 某商业级桌面应用 的模块排除清单 === REM === 参考项目的模块排除清单 ===
set EXCLUDE_MODULES=unittest,test,pytest,_pytest,doctest,pdb,pdbpp set EXCLUDE_MODULES=unittest,test,pytest,_pytest,doctest,pdb,pdbpp
set EXCLUDE_MODULES=%EXCLUDE_MODULES%,setuptools,pip,distutils,pkg_resources set EXCLUDE_MODULES=%EXCLUDE_MODULES%,setuptools,pip,distutils,pkg_resources
set EXCLUDE_MODULES=%EXCLUDE_MODULES%,email.mime,http.server,xmlrpc,pydoc set EXCLUDE_MODULES=%EXCLUDE_MODULES%,email.mime,http.server,xmlrpc,pydoc
@ -211,7 +243,7 @@ if exist dist rd /s /q dist
if exist build rd /s /q build if exist build rd /s /q build
echo. echo.
echo [2/4] Nuitka 编译中(应用 某商业级桌面应用 优化策略)... echo [2/4] Nuitka 编译中(应用 参考项目优化策略)...
echo - CPU 核心: %CPU_CORES% (使用 %BUILD_JOBS% 线程) echo - CPU 核心: %CPU_CORES% (使用 %BUILD_JOBS% 线程)
echo - 模块排除: %EXCLUDE_MODULES% echo - 模块排除: %EXCLUDE_MODULES%
echo. echo.
@ -240,13 +272,13 @@ if %errorlevel% neq 0 (
echo. echo.
echo [3/4] 统计编译结果... echo [3/4] 统计编译结果...
for /f "tokens=3" %%a in ('dir "dist\%APP_NAME%.dist" /s /-c ^| find "个文件"') do set TOTAL_SIZE=%%a for /f %%a in ('powershell -NoProfile -Command "(Get-ChildItem -LiteralPath 'dist\%APP_NAME%.dist' -Recurse -File | Measure-Object -Property Length -Sum).Sum"') do set TOTAL_SIZE=%%a
set TOTAL_SIZE=%TOTAL_SIZE:,=% set TOTAL_SIZE=%TOTAL_SIZE:,=%
set /a SIZE_MB=%TOTAL_SIZE% / 1048576 set /a SIZE_MB=%TOTAL_SIZE% / 1048576
echo - 编译后体积: %SIZE_MB% MB echo - 编译后体积: %SIZE_MB% MB
echo. echo.
echo [4/4] 执行瘦身清理(参考 某商业级桌面应用 策略)... echo [4/4] 执行瘦身清理(参考 参考项目策略)...
powershell -ExecutionPolicy Bypass -File slim_dist.ps1 -DistPath "dist\%APP_NAME%.dist" powershell -ExecutionPolicy Bypass -File slim_dist.ps1 -DistPath "dist\%APP_NAME%.dist"
echo. echo.
@ -256,7 +288,7 @@ echo ========================================
pause pause
``` ```
### 五、dist 瘦身脚本(某商业级桌面应用 级别清理) ### 五、dist 瘦身脚本(参考项目级别清理)
**保存为 `slim_dist.ps1`(和 build_optimized.bat 同目录)** **保存为 `slim_dist.ps1`(和 build_optimized.bat 同目录)**
@ -268,7 +300,7 @@ param(
$ErrorActionPreference = "SilentlyContinue" $ErrorActionPreference = "SilentlyContinue"
Write-Host "`n========================================" -ForegroundColor Cyan Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "dist 瘦身清理(参考 某商业级桌面应用 策略)" -ForegroundColor Cyan Write-Host "dist 瘦身清理(参考 参考项目策略)" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan
if (-not (Test-Path $DistPath)) { if (-not (Test-Path $DistPath)) {
@ -280,8 +312,8 @@ if (-not (Test-Path $DistPath)) {
$InitialSize = (Get-ChildItem -Path $DistPath -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1MB $InitialSize = (Get-ChildItem -Path $DistPath -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1MB
Write-Host "`n初始体积: $([math]::Round($InitialSize, 2)) MB" -ForegroundColor Yellow Write-Host "`n初始体积: $([math]::Round($InitialSize, 2)) MB" -ForegroundColor Yellow
# 某商业级桌面应用 特征:没有 .pdb, .pyi, __pycache__, test 等 # 参考项目特征:没有 .pdb, .pyi, __pycache__, test 等
Write-Host "`n[应用 某商业级桌面应用 的清理策略...]" -ForegroundColor Green Write-Host "`n[应用 参考项目的清理策略...]" -ForegroundColor Green
# 1. 删除调试符号 # 1. 删除调试符号
Write-Host "`n[1/7] 删除 .pdb 调试符号..." -ForegroundColor Green Write-Host "`n[1/7] 删除 .pdb 调试符号..." -ForegroundColor Green
@ -367,7 +399,8 @@ $distInfoDirs = Get-ChildItem -Path $DistPath -Recurse -Directory -Filter "*.dis
$removedCount = 0 $removedCount = 0
$removedSize = 0 $removedSize = 0
foreach ($infoDir in $distInfoDirs) { foreach ($infoDir in $distInfoDirs) {
$filesToRemove = @("RECORD", "INSTALLER", "direct_url.json", "entry_points.txt") # 仅删安装期记账文件;保留 METADATA 与 entry_points.txt运行期被 importlib.metadata 读取,删除会破坏插件发现)
$filesToRemove = @("RECORD", "INSTALLER", "direct_url.json")
foreach ($fileName in $filesToRemove) { foreach ($fileName in $filesToRemove) {
$file = Join-Path $infoDir.FullName $fileName $file = Join-Path $infoDir.FullName $fileName
if (Test-Path $file) { if (Test-Path $file) {
@ -397,9 +430,9 @@ Write-Host "最终体积: $([math]::Round($FinalSize, 2)) MB" -ForegroundColor G
Write-Host "节省空间: $([math]::Round($SavedSize, 2)) MB ($([math]::Round($SavedPercent, 1))%)" -ForegroundColor Cyan Write-Host "节省空间: $([math]::Round($SavedSize, 2)) MB ($([math]::Round($SavedPercent, 1))%)" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan Write-Host "========================================`n" -ForegroundColor Cyan
# 对比 某商业级桌面应用 # 对比 参考项目
Write-Host "[对比参考]" -ForegroundColor Yellow Write-Host "[对比参考]" -ForegroundColor Yellow
Write-Host "某商业级桌面应用 总体积: 323 MB (包含 PyQt, OpenCV, Playwright 等重量级库)" -ForegroundColor Gray Write-Host "参考项目总体积: 323 MB (包含 PyQt, OpenCV, Playwright 等重量级库)" -ForegroundColor Gray
Write-Host "如果你的项目是纯 Tkinter + 标准库,目标应该在 80-150 MB" -ForegroundColor Gray Write-Host "如果你的项目是纯 Tkinter + 标准库,目标应该在 80-150 MB" -ForegroundColor Gray
``` ```
@ -412,7 +445,7 @@ Write-Host "如果你的项目是纯 Tkinter + 标准库,目标应该在 80-15
```python ```python
""" """
DLL 依赖分析工具 DLL 依赖分析工具
参考 某商业级桌面应用 的 DLL 管理策略,帮助识别体积大户和优化建议 参考 参考项目的 DLL 管理策略,帮助识别体积大户和优化建议
""" """
import sys import sys
from pathlib import Path from pathlib import Path
@ -426,7 +459,7 @@ def analyze_dlls(dist_path: str):
return return
print("=" * 70) print("=" * 70)
print("DLL 依赖分析(参考 某商业级桌面应用 策略)") print("DLL 依赖分析(参考 参考项目策略)")
print("=" * 70) print("=" * 70)
# 收集所有 DLL # 收集所有 DLL
@ -445,8 +478,8 @@ def analyze_dlls(dist_path: str):
print(f"\n总 DLL 数量: {len(dll_files)}") print(f"\n总 DLL 数量: {len(dll_files)}")
print(f"总 DLL 体积: {total_size / 1024 / 1024:.2f} MB\n") print(f"总 DLL 体积: {total_size / 1024 / 1024:.2f} MB\n")
# 某商业级桌面应用 对比 # 参考项目对比
print("[对比参考] 某商业级桌面应用 的 DLL 情况:") print("[对比参考] 参考项目的 DLL 情况:")
print(" - 总数量: 71 个") print(" - 总数量: 71 个")
print(" - 总体积: 93.23 MB") print(" - 总体积: 93.23 MB")
print(" - 最大的: libopenblas (26.85 MB), opengl32sw (15.25 MB)\n") print(" - 最大的: libopenblas (26.85 MB), opengl32sw (15.25 MB)\n")
@ -456,7 +489,7 @@ def analyze_dlls(dist_path: str):
if large_dlls: if large_dlls:
print("=" * 70) print("=" * 70)
print("⚠️ 大于 3MB 的 DLL需重点关注") print("WARNING: 大于 3MB 的 DLL需重点关注")
print("=" * 70) print("=" * 70)
for dll, size in large_dlls: for dll, size in large_dlls:
@ -471,21 +504,21 @@ def analyze_dlls(dist_path: str):
suggestions = get_optimization_suggestion(name_lower) suggestions = get_optimization_suggestion(name_lower)
if suggestions: if suggestions:
for suggestion in suggestions: for suggestion in suggestions:
print(f" 💡 {suggestion}") print(f" {suggestion}")
# 检查冗余 DLL # 检查冗余 DLL
print("\n" + "=" * 70) print("\n" + "=" * 70)
print("🔍 冗余检查") print(" 冗余检查")
print("=" * 70) print("=" * 70)
# 检查调试版本 # 检查调试版本
debug_dlls = [dll for dll, _ in dll_data if dll.stem.endswith('d')] debug_dlls = [dll for dll, _ in dll_data if dll.stem.endswith('d')]
if debug_dlls: if debug_dlls:
print(f"\n⚠️ 发现 {len(debug_dlls)} 个调试版本 DLL可以删除:") print(f"\nWARNING: 发现 {len(debug_dlls)} 个调试版本 DLL可以删除:")
for dll in debug_dlls: for dll in debug_dlls:
print(f" - {dll.name}") print(f" - {dll.name}")
else: else:
print("\n 未发现调试版本 DLL已优化") print("\nPASS: 未发现调试版本 DLL已优化")
# VC++ Runtime # VC++ Runtime
vc_runtimes = [dll for dll, _ in dll_data if 'vcruntime' in dll.name.lower() or 'msvcp' in dll.name.lower()] vc_runtimes = [dll for dll, _ in dll_data if 'vcruntime' in dll.name.lower() or 'msvcp' in dll.name.lower()]
@ -494,11 +527,11 @@ def analyze_dlls(dist_path: str):
for dll in vc_runtimes: for dll in vc_runtimes:
size_mb = dll.stat().st_size / 1024 / 1024 size_mb = dll.stat().st_size / 1024 / 1024
print(f" - {dll.name} ({size_mb:.2f} MB)") print(f" - {dll.name} ({size_mb:.2f} MB)")
print(" 💡 这些是必需的,某商业级桌面应用 也包含了这些文件") print(" 这些是必需的,参考项目也包含了这些文件")
# 全部 DLL 列表 # 全部 DLL 列表
print("\n" + "=" * 70) print("\n" + "=" * 70)
print("📋 完整 DLL 列表(按体积排序,前 20") print(" 完整 DLL 列表(按体积排序,前 20")
print("=" * 70) print("=" * 70)
print(f"\n{'体积 (MB)':>10} {'文件名':<30} 位置") print(f"\n{'体积 (MB)':>10} {'文件名':<30} 位置")
print("-" * 70) print("-" * 70)
@ -519,26 +552,26 @@ def get_optimization_suggestion(dll_name: str) -> list:
suggestions = [] suggestions = []
if "openblas" in dll_name or "mkl" in dll_name: if "openblas" in dll_name or "mkl" in dll_name:
suggestions.append("数学运算库,某商业级桌面应用 的 libopenblas 有 26.85 MB") suggestions.append("数学运算库,参考项目的 libopenblas 有 26.85 MB")
suggestions.append("如不需要高性能计算可考虑轻量版") suggestions.append("如不需要高性能计算可考虑轻量版")
elif "opencv" in dll_name or "ffmpeg" in dll_name: elif "opencv" in dll_name or "ffmpeg" in dll_name:
suggestions.append("OpenCV 相关,某商业级桌面应用 的 opencv_videoio_ffmpeg 有 18.48 MB") suggestions.append("OpenCV 相关,参考项目的 opencv_videoio_ffmpeg 有 18.48 MB")
suggestions.append("考虑用 opencv-python-headless") suggestions.append("考虑用 opencv-python-headless")
elif "qt5" in dll_name or "qt6" in dll_name or "pyside" in dll_name: elif "qt5" in dll_name or "qt6" in dll_name or "pyside" in dll_name:
suggestions.append("Qt 库,某商业级桌面应用 的 Qt5Core 有 5.13 MB") suggestions.append("Qt 库,参考项目的 Qt5Core 有 5.13 MB")
suggestions.append("可排除不需要的模块WebEngine, 3D, Charts") suggestions.append("可排除不需要的模块WebEngine, 3D, Charts")
elif "opengl" in dll_name and "sw" in dll_name: elif "opengl" in dll_name and "sw" in dll_name:
suggestions.append("OpenGL 软件渲染器,某商业级桌面应用 保留了 15.25 MB") suggestions.append("OpenGL 软件渲染器,参考项目保留了 15.25 MB")
suggestions.append("通常可以删除(使用硬件渲染)") suggestions.append("通常可以删除(使用硬件渲染)")
elif "d3dcompiler" in dll_name: elif "d3dcompiler" in dll_name:
suggestions.append("DirectX 编译器,某商业级桌面应用 有 3.53 MB") suggestions.append("DirectX 编译器,参考项目有 3.53 MB")
elif "mfc140" in dll_name: elif "mfc140" in dll_name:
suggestions.append("MFC 库,某商业级桌面应用 有 4.89 MB") suggestions.append("MFC 库,参考项目有 4.89 MB")
return suggestions return suggestions
@ -559,7 +592,7 @@ python analyze_dlls.py dist/你的软件名.dist
--- ---
## 📋 完整优化工作流 ## 完整优化工作流
### 步骤 1修改编译脚本配置 ### 步骤 1修改编译脚本配置
@ -606,7 +639,7 @@ Remove-Item "opengl32sw.dll" -Force
--- ---
## 🎯 VC++ 运行库处理方案 ## VC++ 运行库处理方案
### 方案一:静态链接(推荐) ### 方案一:静态链接(推荐)
```bash ```bash
@ -617,24 +650,27 @@ nuitka --static-libpython=yes ...
在 Inno Setup 脚本中添加: 在 Inno Setup 脚本中添加:
```iss ```iss
; WARNING: VC++ 运行库架构必须与 Python/Nuitka 构建架构一致。
; 本 skill 推荐 32 位 Python故默认捆绑 vc_redist.x86.exe
; 若用 64 位 Python 编译,请把下面两处改为 vc_redist.x64.exe。
[Files] [Files]
Source: "{#MySourceDir}\..\vc_redist.x64.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall Source: "{#MySourceDir}\..\vc_redist.x86.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
[Run] [Run]
Filename: "{tmp}\vc_redist.x64.exe"; Parameters: "/quiet /norestart"; StatusMsg: "正在安装运行库..."; Flags: waituntilterminated Filename: "{tmp}\vc_redist.x86.exe"; Parameters: "/quiet /norestart"; StatusMsg: "正在安装运行库..."; Flags: waituntilterminated
``` ```
> 下载地址:[Microsoft Visual C++ Redistributable](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist) > 下载地址:[Microsoft Visual C++ Redistributable](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist)
--- ---
## 📜 Inno Setup 脚本模板(商业终极版) ## Inno Setup 脚本模板(商业终极版)
```iss ```iss
; ===================================================================== ; =====================================================================
; ⚠️ 商业级 Python 安装脚本 (Inno Setup 6.x) ; WARNING: 商业级 Python 安装脚本 (Inno Setup 6.x)
; 特性LZMA2 极限压缩 | 全中文 | 完整元数据 | 无残留卸载 ; 特性LZMA2 极限压缩 | 全中文 | 完整元数据 | 无残留卸载
; 参考:某商业级桌面应用 (323 MB, LZMA2 压缩) ; 参考:参考项目(323 MB, LZMA2 压缩)
; ===================================================================== ; =====================================================================
; --- 1. 参数定义 --- ; --- 1. 参数定义 ---
@ -675,13 +711,16 @@ SetupIconFile={#MyIconPath}
UninstallDisplayIcon={app}\{#MyAppExeName} UninstallDisplayIcon={app}\{#MyAppExeName}
#endif #endif
; --- 🚀 核心压缩 (参考 某商业级桌面应用) --- ; --- 核心压缩 (参考 参考项目) ---
Compression=lzma2/ultra64 Compression=lzma2/ultra64
SolidCompression=yes SolidCompression=yes
LZMAUseSeparateProcess=yes LZMAUseSeparateProcess=yes
; --- 架构 --- ; --- 架构 ---
ArchitecturesInstallIn64BitMode=x64compatible ; 注意:仅 64 位 Python 构建才设此项。本 skill 推荐 32 位 Python——
; 32 位构建请保持注释,使应用按 32 位安装并与上面捆绑的 vc_redist.x86.exe 匹配。
; 仅当用 64 位 Python 编译时才取消注释。
;ArchitecturesInstallIn64BitMode=x64compatible
[Languages] [Languages]
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl" Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
@ -732,7 +771,7 @@ Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppName}}
### Q2: 安装包体积过大? ### Q2: 安装包体积过大?
**优化方法** **优化方法**
1. 使用 32 位 Python 编译(节省 20-30% 1. 使用 32 位 Python 编译(节省 20-30%
2. 应用 某商业级桌面应用 的模块排除清单 2. 应用 参考项目的模块排除清单
3. 启用 Anti-Bloat 插件 3. 启用 Anti-Bloat 插件
4. 执行 dist 文件夹瘦身脚本 4. 执行 dist 文件夹瘦身脚本
5. 分析 DLL移除不必要的大文件 5. 分析 DLL移除不必要的大文件
@ -754,7 +793,7 @@ Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppName}}
- **安装后提示缺少 python3xx.dll**:必须使用 Nuitka `--standalone`;确认 dist 内存在该 dll不要打单文件版。 - **安装后提示缺少 python3xx.dll**:必须使用 Nuitka `--standalone`;确认 dist 内存在该 dll不要打单文件版。
- **安装后点击无反应**GUI 启动期可能被重依赖阻塞;将重依赖延迟到"开始导出"再 import添加日志排查。 - **安装后点击无反应**GUI 启动期可能被重依赖阻塞;将重依赖延迟到"开始导出"再 import添加日志排查。
- **Nuitka + MinGW 在非 ASCII 路径报错**:把源码复制到 ASCII 目录再编译;设置 `PYTHONIOENCODING=utf-8` - **Nuitka + MinGW 在非 ASCII 路径报错**:把源码复制到 ASCII 目录再编译;设置 `PYTHONIOENCODING=utf-8`
- **Inno Setup 警告 `x64` 已弃用**:改为 `ArchitecturesInstallIn64BitMode=x64compatible` - **Inno Setup 警告 `x64` 已弃用(仅 64 位构建需要 64 位安装模式时)**:改为 `ArchitecturesInstallIn64BitMode=x64compatible`32 位构建无需此项
- **`--disable-console` 已废弃**:改用 `--windows-console-mode=disable` - **`--disable-console` 已废弃**:改用 `--windows-console-mode=disable`
- **dist 出现 `_nuitka_temp.exe`**:在 [Files] 中排除它。 - **dist 出现 `_nuitka_temp.exe`**:在 [Files] 中排除它。
@ -765,15 +804,15 @@ Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppName}}
| 优化组合 | 体积减少 | 启动提升 | 风险等级 | | 优化组合 | 体积减少 | 启动提升 | 风险等级 |
|----------|----------|----------|----------| |----------|----------|----------|----------|
| 基础编译 | 基准 | 基准 | 无 | | 基础编译 | 基准 | 基准 | 无 |
| + `--lto=yes` | 5-10% | 10-20% | 无 | | + `--lto=yes` | 5-10% | 10-20% | PASS: 无 |
| + anti-bloat | 15-25% | - | 无 | | + anti-bloat | 15-25% | - | PASS: 无 |
| + 模块排除 | 20-35% | 5% | 无 | | + 模块排除 | 20-35% | 5% | PASS: 无 |
| + dist 瘦身 | 25-40% | - | 无 | | + dist 瘦身 | 25-40% | - | PASS: 无 |
| + 32 位编译 | 40-60% | - | 无 | | + 32 位编译 | 40-60% | - | PASS: 无 |
| **全部组合** | **45-65%** | **15-25%** | **无风险** | | **全部组合** | **45-65%** | **15-25%** | PASS: **无风险** |
> ⚠️ **不建议使用 UPX 压缩**,虽然能进一步减小体积,但极易触发杀毒软件误报。 > WARNING: **不建议使用 UPX 压缩**,虽然能进一步减小体积,但极易触发杀毒软件误报。
--- ---
**基于 某商业级桌面应用 实战经验优化,助你打造商业级安装包!** 🚀 **基于 参考项目实战经验优化,助你打造商业级安装包!**