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 - folder slimming, DLL footprint analysis, 32-bit vs 64-bit size tradeoffs - Inno Setup packa…

}\n$testSize = 0\nforeach ($dir in $testDirs) {\n $size = (Get-ChildItem -Path $dir.FullName -Recurse -File | Measure-Object -Property Length -Sum).Sum\n $testSize += $size\n Remove-Item -Path $dir.FullName -Recurse -Force\n}\nif ($testDirs.Count -gt 0) {\n Write-Host \" 删除 $($testDirs.Count) 个目录,节省 $([math]::Round($testSize / 1MB, 2)) MB\"\n} else {\n Write-Host \" 未发现测试目录(已优化)\" -ForegroundColor Gray\n}\n\n# 5. 删除文档和示例\nWrite-Host \"`n[5/7] 删除 docs/examples 文档目录...\" -ForegroundColor Green\n$docDirs = Get-ChildItem -Path $DistPath -Recurse -Directory | Where-Object { $_.Name -match '^(docs|examples|samples|demo)

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 - folder slimming, DLL footprint analysis, 32-bit vs 64-bit size tradeoffs - Inno Setup packa…

}\n$docSize = 0\nforeach ($dir in $docDirs) {\n $size = (Get-ChildItem -Path $dir.FullName -Recurse -File | Measure-Object -Property Length -Sum).Sum\n $docSize += $size\n Remove-Item -Path $dir.FullName -Recurse -Force\n}\nif ($docDirs.Count -gt 0) {\n Write-Host \" 删除 $($docDirs.Count) 个目录,节省 $([math]::Round($docSize / 1MB, 2)) MB\"\n} else {\n Write-Host \" 未发现文档目录(已优化)\" -ForegroundColor Gray\n}\n\n# 6. 删除 .pyc 文件\nWrite-Host \"`n[6/7] 删除 .pyc 字节码...\" -ForegroundColor Green\n$pycFiles = Get-ChildItem -Path $DistPath -Recurse -Include *.pyc -File\n$pycSize = ($pycFiles | Measure-Object -Property Length -Sum).Sum / 1MB\nif ($pycFiles.Count -gt 0) {\n $pycFiles | Remove-Item -Force\n Write-Host \" 删除 $($pycFiles.Count) 个文件,节省 $([math]::Round($pycSize, 2)) MB\"\n} else {\n Write-Host \" 未发现 .pyc 文件(已优化)\" -ForegroundColor Gray\n}\n\n# 7. 精简 .dist-info 元数据\nWrite-Host \"`n[7/7] 精简 .dist-info 元数据...\" -ForegroundColor Green\n$distInfoDirs = Get-ChildItem -Path $DistPath -Recurse -Directory -Filter \"*.dist-info\"\n$removedCount = 0\n$removedSize = 0\nforeach ($infoDir in $distInfoDirs) {\n # 仅删安装期记账文件;保留 METADATA 与 entry_points.txt(运行期被 importlib.metadata 读取,删除会破坏插件发现)\n $filesToRemove = @(\"RECORD\", \"INSTALLER\", \"direct_url.json\")\n foreach ($fileName in $filesToRemove) {\n $file = Join-Path $infoDir.FullName $fileName\n if (Test-Path $file) {\n $size = (Get-Item $file).Length\n $removedSize += $size\n Remove-Item $file -Force\n $removedCount++\n }\n }\n}\nif ($removedCount -gt 0) {\n Write-Host \" 删除 $removedCount 个元数据文件,节省 $([math]::Round($removedSize / 1MB, 2)) MB\"\n} else {\n Write-Host \" 未发现可清理的元数据(已优化)\" -ForegroundColor Gray\n}\n\n# 统计最终体积\n$FinalSize = (Get-ChildItem -Path $DistPath -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1MB\n$SavedSize = $InitialSize - $FinalSize\n$SavedPercent = if ($InitialSize -gt 0) { ($SavedSize / $InitialSize) * 100 } else { 0 }\n\nWrite-Host \"`n========================================\" -ForegroundColor Cyan\nWrite-Host \"清理完成!\" -ForegroundColor Green\nWrite-Host \"========================================\" -ForegroundColor Cyan\nWrite-Host \"初始体积: $([math]::Round($InitialSize, 2)) MB\" -ForegroundColor Yellow\nWrite-Host \"最终体积: $([math]::Round($FinalSize, 2)) MB\" -ForegroundColor Green\nWrite-Host \"节省空间: $([math]::Round($SavedSize, 2)) MB ($([math]::Round($SavedPercent, 1))%)\" -ForegroundColor Cyan\nWrite-Host \"========================================`n\" -ForegroundColor Cyan\n\n# 对比 参考项目\nWrite-Host \"[对比参考]\" -ForegroundColor Yellow\nWrite-Host \"参考项目总体积: 323 MB (包含 PyQt, OpenCV, Playwright 等重量级库)\" -ForegroundColor Gray\nWrite-Host \"如果你的项目是纯 Tkinter + 标准库,目标应该在 80-150 MB\" -ForegroundColor Gray\n```\n\n**预期效果**:节省 **15-30%** 体积\n\n### 六、DLL 依赖分析工具\n\n**保存为 `analyze_dlls.py`(用于找出体积大户)**:\n\n```python\n\"\"\"\nDLL 依赖分析工具\n参考 参考项目的 DLL 管理策略,帮助识别体积大户和优化建议\n\"\"\"\nimport sys\nfrom pathlib import Path\n\ndef analyze_dlls(dist_path: str):\n \"\"\"分析 dist 目录中的 DLL 依赖\"\"\"\n dist_dir = Path(dist_path)\n\n if not dist_dir.exists():\n print(f\"[错误] 目录不存在: {dist_path}\")\n return\n\n print(\"=\" * 70)\n print(\"DLL 依赖分析(参考 参考项目策略)\")\n print(\"=\" * 70)\n\n # 收集所有 DLL\n dll_files = list(dist_dir.rglob(\"*.dll\"))\n\n if not dll_files:\n print(\"\\n未发现 DLL 文件\")\n return\n\n # 按大小排序\n dll_data = [(dll, dll.stat().st_size) for dll in dll_files]\n dll_data.sort(key=lambda x: x[1], reverse=True)\n\n total_size = sum(size for _, size in dll_data)\n\n print(f\"\\n总 DLL 数量: {len(dll_files)}\")\n print(f\"总 DLL 体积: {total_size / 1024 / 1024:.2f} MB\\n\")\n\n # 参考项目对比\n print(\"[对比参考] 参考项目的 DLL 情况:\")\n print(\" - 总数量: 71 个\")\n print(\" - 总体积: 93.23 MB\")\n print(\" - 最大的: libopenblas (26.85 MB), opengl32sw (15.25 MB)\\n\")\n\n # 分析大于 3MB 的 DLL\n large_dlls = [(dll, size) for dll, size in dll_data if size > 3 * 1024 * 1024]\n\n if large_dlls:\n print(\"=\" * 70)\n print(\"WARNING: 大于 3MB 的 DLL(需重点关注)\")\n print(\"=\" * 70)\n\n for dll, size in large_dlls:\n size_mb = size / 1024 / 1024\n relative_path = dll.relative_to(dist_dir)\n name_lower = dll.name.lower()\n\n print(f\"\\n{size_mb:8.2f} MB {dll.name}\")\n print(f\" 位置: {relative_path.parent}\")\n\n # 优化建议\n suggestions = get_optimization_suggestion(name_lower)\n if suggestions:\n for suggestion in suggestions:\n print(f\" {suggestion}\")\n\n # 检查冗余 DLL\n print(\"\\n\" + \"=\" * 70)\n print(\" 冗余检查\")\n print(\"=\" * 70)\n\n # 检查调试版本\n debug_dlls = [dll for dll, _ in dll_data if dll.stem.endswith('d')]\n if debug_dlls:\n print(f\"\\nWARNING: 发现 {len(debug_dlls)} 个调试版本 DLL(可以删除):\")\n for dll in debug_dlls:\n print(f\" - {dll.name}\")\n else:\n print(\"\\nPASS: 未发现调试版本 DLL(已优化)\")\n\n # VC++ Runtime\n vc_runtimes = [dll for dll, _ in dll_data if 'vcruntime' in dll.name.lower() or 'msvcp' in dll.name.lower()]\n if vc_runtimes:\n print(f\"\\n[VC++ Runtime 库] 发现 {len(vc_runtimes)} 个:\")\n for dll in vc_runtimes:\n size_mb = dll.stat().st_size / 1024 / 1024\n print(f\" - {dll.name} ({size_mb:.2f} MB)\")\n print(\" 这些是必需的,参考项目也包含了这些文件\")\n\n # 全部 DLL 列表\n print(\"\\n\" + \"=\" * 70)\n print(\" 完整 DLL 列表(按体积排序,前 20)\")\n print(\"=\" * 70)\n print(f\"\\n{'体积 (MB)':>10} {'文件名':\u003c30} 位置\")\n print(\"-\" * 70)\n\n for dll, size in dll_data[:20]:\n size_mb = size / 1024 / 1024\n relative_path = dll.relative_to(dist_dir)\n location = str(relative_path.parent) if relative_path.parent != Path('.') else \"根目录\"\n print(f\"{size_mb:10.2f} {dll.name:\u003c30} {location}\")\n\n if len(dll_data) > 20:\n remaining_size = sum(size for _, size in dll_data[20:]) / 1024 / 1024\n print(f\"... 还有 {len(dll_data) - 20} 个 DLL,共 {remaining_size:.2f} MB\")\n\n\ndef get_optimization_suggestion(dll_name: str) -> list:\n \"\"\"根据 DLL 名称给出优化建议\"\"\"\n suggestions = []\n\n if \"openblas\" in dll_name or \"mkl\" in dll_name:\n suggestions.append(\"数学运算库,参考项目的 libopenblas 有 26.85 MB\")\n suggestions.append(\"如不需要高性能计算可考虑轻量版\")\n\n elif \"opencv\" in dll_name or \"ffmpeg\" in dll_name:\n suggestions.append(\"OpenCV 相关,参考项目的 opencv_videoio_ffmpeg 有 18.48 MB\")\n suggestions.append(\"考虑用 opencv-python-headless\")\n\n elif \"qt5\" in dll_name or \"qt6\" in dll_name or \"pyside\" in dll_name:\n suggestions.append(\"Qt 库,参考项目的 Qt5Core 有 5.13 MB\")\n suggestions.append(\"可排除不需要的模块(WebEngine, 3D, Charts)\")\n\n elif \"opengl\" in dll_name and \"sw\" in dll_name:\n suggestions.append(\"OpenGL 软件渲染器,参考项目保留了 15.25 MB\")\n suggestions.append(\"通常可以删除(使用硬件渲染)\")\n\n elif \"d3dcompiler\" in dll_name:\n suggestions.append(\"DirectX 编译器,参考项目有 3.53 MB\")\n\n elif \"mfc140\" in dll_name:\n suggestions.append(\"MFC 库,参考项目有 4.89 MB\")\n\n return suggestions\n\n\nif __name__ == \"__main__\":\n if len(sys.argv) \u003c 2:\n print(\"用法: python analyze_dlls.py \u003cdist目录路径>\")\n print(\"示例: python analyze_dlls.py dist/main.dist\")\n sys.exit(1)\n\n analyze_dlls(sys.argv[1])\n```\n\n**使用方法**:\n```bash\npython analyze_dlls.py dist/你的软件名.dist\n```\n\n---\n\n## 完整优化工作流\n\n### 步骤 1:修改编译脚本配置\n\n编辑 `build_optimized.bat`,修改这 3 行:\n\n```batch\nset APP_NAME=你的软件名 REM 改成实际名称\nset MAIN_FILE=main.py REM 你的主程序文件\nset ICON_FILE=icon.ico REM 你的图标文件\n```\n\n### 步骤 2:一键编译+瘦身\n\n```bash\n# 在项目根目录执行\nbuild_optimized.bat\n```\n\n### 步骤 3:分析 DLL 依赖\n\n```bash\npython analyze_dlls.py dist/你的软件名.dist\n```\n\n### 步骤 4:根据分析结果优化\n\n**如果用了 OpenCV** → 改用无头版\n```bash\npip uninstall opencv-python\npip install opencv-python-headless\n```\n\n**如果用了 Qt** → 排除不需要的模块\n```batch\n# 在编译命令中添加\n--nofollow-import-to=PyQt5.QtWebEngine,PyQt5.Qt3D,PyQt5.QtCharts\n```\n\n**删除软件渲染器**(如果不需要)\n```powershell\n# 在 dist 目录执行\nRemove-Item \"opengl32sw.dll\" -Force\n```\n\n---\n\n## VC++ 运行库处理方案\n\n### 方案一:静态链接(推荐)\n```bash\nnuitka --static-libpython=yes ...\n```\n\n### 方案二:捆绑运行库安装(商业发布推荐)\n在 Inno Setup 脚本中添加:\n\n```iss\n; WARNING: VC++ 运行库架构必须与 Python/Nuitka 构建架构一致。\n; 本 skill 推荐 32 位 Python,故默认捆绑 vc_redist.x86.exe;\n; 若用 64 位 Python 编译,请把下面两处改为 vc_redist.x64.exe。\n[Files]\nSource: \"{#MySourceDir}\\..\\vc_redist.x86.exe\"; DestDir: \"{tmp}\"; Flags: deleteafterinstall\n\n[Run]\nFilename: \"{tmp}\\vc_redist.x86.exe\"; Parameters: \"/quiet /norestart\"; StatusMsg: \"正在安装运行库...\"; Flags: waituntilterminated\n```\n\n> 下载地址:[Microsoft Visual C++ Redistributable](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist)\n\n---\n\n## Inno Setup 脚本模板(商业终极版)\n\n```iss\n; =====================================================================\n; WARNING: 商业级 Python 安装脚本 (Inno Setup 6.x)\n; 特性:LZMA2 极限压缩 | 全中文 | 完整元数据 | 无残留卸载\n; 参考:参考项目(323 MB, LZMA2 压缩)\n; =====================================================================\n\n; --- 1. 参数定义 ---\n#define MyAppName \"{{APP_NAME}}\"\n#define MyAppVersion \"{{APP_VERSION}}\"\n#define MyAppPublisher \"{{PUBLISHER}}\"\n#define MyAppURL \"{{APP_URL}}\"\n#define MyAppExeName \"{{EXE_NAME}}\"\n#define MySourceDir \"{{SOURCE_DIR}}\"\n#define MyOutputDir \"{{OUTPUT_DIR}}\"\n;#define MyIconPath \"{{ICON_PATH}}\"\n\n[Setup]\n; --- 身份识别 ---\nAppId={{GENERATE_RANDOM_GUID}}\nAppName={#MyAppName}\nAppVersion={#MyAppVersion}\nAppPublisher={#MyAppPublisher}\nAppPublisherURL={#MyAppURL}\nAppSupportURL={#MyAppURL}\nAppUpdatesURL={#MyAppURL}\n\n; --- 安装路径与权限 ---\nDefaultDirName={autopf}\\{#MyAppName}\nDefaultGroupName={#MyAppName}\nDisableDirPage=no\nDisableProgramGroupPage=no\nPrivilegesRequired=admin\n\n; --- 输出设置 ---\nOutputDir={#MyOutputDir}\nOutputBaseFilename=Setup_{#MyAppName}_v{#MyAppVersion}\n\n; --- 视觉体验 ---\nWizardStyle=modern\n#ifdef MyIconPath\nSetupIconFile={#MyIconPath}\nUninstallDisplayIcon={app}\\{#MyAppExeName}\n#endif\n\n; --- 核心压缩 (参考 参考项目) ---\nCompression=lzma2/ultra64\nSolidCompression=yes\nLZMAUseSeparateProcess=yes\n\n; --- 架构 ---\n; 注意:仅 64 位 Python 构建才设此项。本 skill 推荐 32 位 Python——\n; 32 位构建请保持注释,使应用按 32 位安装并与上面捆绑的 vc_redist.x86.exe 匹配。\n; 仅当用 64 位 Python 编译时才取消注释。\n;ArchitecturesInstallIn64BitMode=x64compatible\n\n[Languages]\nName: \"chinesesimplified\"; MessagesFile: \"compiler:Languages\\ChineseSimplified.isl\"\n\n[Files]\nSource: \"{#MySourceDir}\\*\"; DestDir: \"{app}\"; Flags: ignoreversion recursesubdirs createallsubdirs\n\n[UninstallDelete]\nType: filesandordirs; Name: \"{app}\\*\"\n\n[Icons]\nName: \"{autodesktop}\\{#MyAppName}\"; Filename: \"{app}\\{#MyAppExeName}\"; Tasks: desktopicon\nName: \"{group}\\{#MyAppName}\"; Filename: \"{app}\\{#MyAppExeName}\"\nName: \"{group}\\卸载 {#MyAppName}\"; Filename: \"{uninstallexe}\"\n\n[Tasks]\nName: \"desktopicon\"; Description: \"{cm:CreateDesktopIcon}\"; GroupDescription: \"{cm:AdditionalIcons}\"; Flags: unchecked\n\n[Run]\nFilename: \"{app}\\{#MyAppExeName}\"; Description: \"{cm:LaunchProgram,{#MyAppName}}\"; Flags: nowait postinstall skipifsilent\n```\n\n---\n\n## 占位符说明\n\n| 占位符 | 说明 | 示例值 |\n|--------|------|--------|\n| `{{APP_NAME}}` | 软件显示名称 | `红墨批注` |\n| `{{APP_VERSION}}` | 版本号 | `1.0.0` |\n| `{{PUBLISHER}}` | 发布者/公司名 | `MyCompany` |\n| `{{APP_URL}}` | 官网地址 | `https://example.com` |\n| `{{EXE_NAME}}` | 主程序文件名 | `RedInk.exe` |\n| `{{SOURCE_DIR}}` | Nuitka dist 文件夹路径 | `D:\\project\\dist\\RedInk.dist` |\n| `{{OUTPUT_DIR}}` | 安装包输出路径 | `D:\\project\\output` |\n| `{{ICON_PATH}}` | 图标文件路径 | `D:\\project\\icon.ico` |\n| `{{GENERATE_RANDOM_GUID}}` | **需生成唯一GUID** | 使用 Inno Setup \"Tools > Generate GUID\" |\n\n---\n\n## 常见问题 (FAQ)\n\n### Q1: 安装后双击程序无反应?\n1. 打开 CMD,手动运行 exe 查看错误信息\n2. 检查是否缺少 VC++ 运行库\n3. 检查 Nuitka 编译是否成功\n\n### Q2: 安装包体积过大?\n**优化方法**:\n1. 使用 32 位 Python 编译(节省 20-30%)\n2. 应用 参考项目的模块排除清单\n3. 启用 Anti-Bloat 插件\n4. 执行 dist 文件夹瘦身脚本\n5. 分析 DLL,移除不必要的大文件\n\n### Q3: 杀毒软件误报?\n**解决方案**:\n- 提交到主流杀毒厂商进行白名单申请\n- 购买代码签名证书(推荐:Sectigo, DigiCert)\n- 避免使用 UPX 压缩\n\n### Q4: 安装时提示 Windows 已保护你的电脑?\n- 购买 EV 代码签名证书(可立即获得信任)\n- 普通代码签名证书需要积累安装量后逐渐获得信任\n\n---\n\n## 实战问题处理记录(更新 2026-02-07)\n\n- **安装后提示缺少 python3xx.dll**:必须使用 Nuitka `--standalone`;确认 dist 内存在该 dll;不要打单文件版。\n- **安装后点击无反应**:GUI 启动期可能被重依赖阻塞;将重依赖延迟到\"开始导出\"再 import;添加日志排查。\n- **Nuitka + MinGW 在非 ASCII 路径报错**:把源码复制到 ASCII 目录再编译;设置 `PYTHONIOENCODING=utf-8`。\n- **Inno Setup 警告 `x64` 已弃用(仅 64 位构建需要 64 位安装模式时)**:改为 `ArchitecturesInstallIn64BitMode=x64compatible`;32 位构建无需此项。\n- **`--disable-console` 已废弃**:改用 `--windows-console-mode=disable`。\n- **dist 出现 `_nuitka_temp.exe`**:在 [Files] 中排除它。\n\n---\n\n## 优化效果预期\n\n| 优化组合 | 体积减少 | 启动提升 | 风险等级 |\n|----------|----------|----------|----------|\n| 基础编译 | 基准 | 基准 | 无 |\n| + `--lto=yes` | 5-10% | 10-20% | PASS: 无 |\n| + anti-bloat | 15-25% | - | PASS: 无 |\n| + 模块排除 | 20-35% | 5% | PASS: 无 |\n| + dist 瘦身 | 25-40% | - | PASS: 无 |\n| + 32 位编译 | 40-60% | - | PASS: 无 |\n| **全部组合** | **45-65%** | **15-25%** | PASS: **无风险** |\n\n> WARNING: **不建议使用 UPX 压缩**,虽然能进一步减小体积,但极易触发杀毒软件误报。\n\n---\n\n**基于 参考项目实战经验优化,助你打造商业级安装包!**","attachment_filenames":[],"attachments":[],"content_json":{"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"text":"Generating Python Installer (Commercial-Grade)","type":"text"}]},{"type":"paragraph","content":[{"text":"You are a ","type":"text"},{"text":"Python commercial deployment expert","type":"text","marks":[{"type":"strong"}]},{"text":". Your goal is the ","type":"text"},{"text":"smallest, fastest-starting, cleanest","type":"text","marks":[{"type":"strong"}]},{"text":" Windows installer. The core approach is ","type":"text"},{"text":"\"Nuitka folder mode (dist) + Inno Setup packaging\"","type":"text","marks":[{"type":"strong"}]},{"text":" — no single-file builds, no stray console window.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"When to Activate","type":"text"}]},{"type":"paragraph","content":[{"text":"Activate when the user explicitly asks for ","type":"text"},{"text":"advanced","type":"text","marks":[{"type":"strong"}]},{"text":" Python packaging or size/startup optimization on Windows:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Nuitka extreme / commercial-grade compilation, smallest-size or fastest-startup builds","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"dist","type":"text","marks":[{"type":"code_inline"}]},{"text":" folder slimming, DLL footprint analysis, 32-bit vs 64-bit size tradeoffs","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Inno Setup packaging with full metadata and a clean, residue-free uninstall","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"This skill targets advanced size/startup optimization — not basic one-file \"script to exe\" conversion.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"How It Works","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Confirm build parameters","type":"text","marks":[{"type":"strong"}]},{"text":" — app name, version, publisher, exe name, source/output dirs, icon. Never auto-fill; ask the user.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Verify the source build","type":"text","marks":[{"type":"strong"}]},{"text":" — console disabled, LTO enabled, VC++ runtime present.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Compile with Nuitka","type":"text","marks":[{"type":"strong"}]},{"text":" using the module-exclusion and plugin strategy below.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Slim the ","type":"text","marks":[{"type":"strong"}]},{"text":"dist","type":"text","marks":[{"type":"code_inline"},{"type":"strong"}]},{"text":" folder","type":"text","marks":[{"type":"strong"}]},{"text":" — strip debug symbols, caches, tests, and docs, with safeguards for runtime-required metadata.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Analyze DLLs","type":"text","marks":[{"type":"strong"}]},{"text":" to find and trim the largest dependencies.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Package with Inno Setup","type":"text","marks":[{"type":"strong"}]},{"text":" — LZMA2 ultra compression, full metadata, residue-free uninstall, and an arch-matched VC++ redistributable.","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Examples","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"\"用 Nuitka 把这个 PySide2 项目打成最小体积的商业安装包\" → run the full workflow: recommend 32-bit, exclude WebEngine/3D/Charts, slim ","type":"text"},{"text":"dist","type":"text","marks":[{"type":"code_inline"}]},{"text":", package with Inno Setup.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"\"我的 exe 有 400 MB,怎么瘦身到一半\" → analyze DLLs, switch to ","type":"text"},{"text":"opencv-python-headless","type":"text","marks":[{"type":"code_inline"}]},{"text":", drop ","type":"text"},{"text":"opengl32sw","type":"text","marks":[{"type":"code_inline"}]},{"text":", apply ","type":"text"},{"text":"dist","type":"text","marks":[{"type":"code_inline"}]},{"text":" slimming.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"\"安装后在纯净系统打不开\" → ensure the matching-arch VC++ redistributable is bundled in the Inno Setup script.","type":"text"}]}]}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"核心理念","type":"text"}]},{"type":"paragraph","content":[{"text":"坚持 ","type":"text"},{"text":"\"Nuitka 文件夹模式(dist) + Inno Setup 封装\"","type":"text","marks":[{"type":"strong"}]},{"text":" 方案。拒绝单文件版,拒绝黑窗。","type":"text"}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"实战参考案例(生产级 PySide2 桌面应用,323 MB,含 OpenCV / Playwright)","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"项目概况","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"总体积","type":"text","marks":[{"type":"strong"}]},{"text":": 323 MB","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"打包工具","type":"text","marks":[{"type":"strong"}]},{"text":": PyInstaller 4.7 (32位)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"主要依赖","type":"text","marks":[{"type":"strong"}]},{"text":": PySide2 (22.52 MB), OpenCV (62.38 MB), Playwright (76.74 MB)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Python 版本","type":"text","marks":[{"type":"strong"}]},{"text":": Python 3.8 (32位)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"DLL 数量","type":"text","marks":[{"type":"strong"}]},{"text":": 71 个,总计 93.23 MB","type":"text"}]}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"关键优化策略","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"PASS: ","type":"text"},{"text":"使用 32 位 Python","type":"text","marks":[{"type":"strong"}]},{"text":" → 体积减少 20-30%","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"PASS: ","type":"text"},{"text":"base_library.zip 压缩标准库","type":"text","marks":[{"type":"strong"}]},{"text":" → 0.74 MB","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"PASS: ","type":"text"},{"text":"精简模块排除","type":"text","marks":[{"type":"strong"}]},{"text":" → 无 pytest/unittest/setuptools","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"PASS: ","type":"text"},{"text":"精简 Qt 插件","type":"text","marks":[{"type":"strong"}]},{"text":" → 只保留必要插件","type":"text"}]}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"体积分布","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"组件","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"体积","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"占比","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"优化建议","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"playwright","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"76.74 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"23.8%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"非必要可移除","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"OpenCV","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"62.38 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"19.3%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"用 opencv-python-headless","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"PySide2","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"22.52 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"7.0%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"排除 WebEngine/3D/Charts","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"其他依赖","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"161.36 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"49.9%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"-","type":"text"}]}]}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"预期效果对比","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"项目类型","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Nuitka 原始","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"优化后","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"参考项目实测","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Tkinter + 标准库","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"150-250 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"80-120 MB","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"-","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"PyQt/PySide","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"200-400 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"120-250 MB","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"323 MB (含 OpenCV 等)","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"含 numpy/pandas","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"300-600 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"180-350 MB","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"-","type":"text"}]}]}]}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"核心工作流 (Workflow) - WARNING: 严格执行","type":"text"}]},{"type":"paragraph","content":[{"text":"当用户请求打包时,按照以下步骤操作:","type":"text"}]},{"type":"paragraph","content":[{"text":"步骤 1:强制参数确认(FAIL: 禁止使用默认值)","type":"text","marks":[{"type":"strong"}]}]},{"type":"blockquote","content":[{"type":"paragraph","content":[{"text":"WARNING: 重要规则:以下所有参数必须逐一向用户确认,禁止自动填充或使用默认值!","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"paragraph","content":[{"text":"必须向用户询问并确认以下信息(","type":"text"},{"text":"等待用户明确回复后才能继续","type":"text","marks":[{"type":"em"}]},{"text":"):","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"参数","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"说明","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"示例","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"软件名称","type":"text","marks":[{"type":"strong"}]},{"text":" (App Name)","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"软件显示名称","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"红墨批注","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"版本号","type":"text","marks":[{"type":"strong"}]},{"text":" (Version)","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"语义化版本号","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"1.0.0","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"发布者/公司名","type":"text","marks":[{"type":"strong"}]},{"text":" (Publisher)","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"控制面板显示的发布者","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"YourCompany","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"主程序","type":"text","marks":[{"type":"strong"}]},{"text":" (Exe Name)","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"主可执行文件名","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"RedInk.exe","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"源路径","type":"text","marks":[{"type":"strong"}]},{"text":" (Source Dir)","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Nuitka dist 文件夹绝对路径","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"D:\\project\\dist","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"输出路径","type":"text","marks":[{"type":"strong"}]},{"text":" (Output Dir)","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"安装包生成位置","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"D:\\project\\output","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"图标路径","type":"text","marks":[{"type":"strong"}]},{"text":" (Icon Path)","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":".ico 文件绝对路径(可选但推荐)","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"D:\\project\\icon.ico","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"官网地址","type":"text","marks":[{"type":"strong"}]},{"text":" (URL)","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"可选,用于控制面板链接","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"https://example.com","type":"text","marks":[{"type":"code_inline"}]}]}]}]}]},{"type":"paragraph","content":[{"text":"询问模板:","type":"text","marks":[{"type":"strong"}]}]},{"type":"blockquote","content":[{"type":"paragraph","content":[{"text":"\"请提供以下打包参数,我需要您逐一确认:","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"软件名称:","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"版本号:","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"发布者/公司名:","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"主程序文件名(如 xxx.exe):","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"源路径(Nuitka dist 文件夹):","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"输出路径(安装包保存位置):","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"图标路径(.ico 文件,可留空):","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"官网地址(可留空):","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"请逐一填写,或回复\"跳过\"表示使用空值。\"","type":"text"}]}]},{"type":"paragraph","content":[{"text":"步骤 2:源文件质量与编译检查(关键)","type":"text","marks":[{"type":"strong"}]},{"text":" 在生成代码之前,必须向用户发出以下","type":"text"},{"text":"关键确认","type":"text","marks":[{"type":"strong"}]},{"text":"(因为 Inno Setup 只是打包工具,无法改变程序本身的运行属性):","type":"text"}]},{"type":"blockquote","content":[{"type":"paragraph","content":[{"text":"\"WARNING: ","type":"text"},{"text":"编译参数检查","type":"text","marks":[{"type":"strong"}]},{"text":":","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"去黑窗","type":"text","marks":[{"type":"strong"}]},{"text":":请确认您的 dist 文件夹是使用 ","type":"text"},{"text":"nuitka --windows-console-mode=disable","type":"text","marks":[{"type":"code_inline"}]},{"text":" 编译的。(否则安装后依然会有黑框)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"高性能","type":"text","marks":[{"type":"strong"}]},{"text":":请确认是否使用了 ","type":"text"},{"text":"--lto=yes","type":"text","marks":[{"type":"code_inline"}]},{"text":"。(否则启动速度可能不理想)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"运行库","type":"text","marks":[{"type":"strong"}]},{"text":":请确保 dist 文件夹内已包含必要的 VC++ 运行库,防止在纯净系统上无法运行。","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"确认源文件已准备好请回复\"确认\",否则请先重新编译。","type":"text","marks":[{"type":"strong"}]},{"text":"\"","type":"text"}]}]},{"type":"paragraph","content":[{"text":"步骤 3:生成代码","type":"text","marks":[{"type":"strong"}]},{"text":" 用户确认后,输出包含 ","type":"text"},{"text":"完整元数据","type":"text","marks":[{"type":"strong"}]},{"text":" 和 ","type":"text"},{"text":"卸载图标修复","type":"text","marks":[{"type":"strong"}]},{"text":" 的代码。","type":"text"}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"Nuitka 极限优化编译(基于 参考项目经验)","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"一、32 位 vs 64 位选择策略","type":"text"}]},{"type":"paragraph","content":[{"text":"参考项目使用 32 位 Python 的原因","type":"text","marks":[{"type":"strong"}]},{"text":":","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"组件","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"64位体积","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"32位体积","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"节省","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"python3x.dll","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"~4.5 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"~3.8 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"15%","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Qt5Core.dll","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"~8 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"~5 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"37%","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"numpy","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"~30 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"~20 MB","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"33%","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"总体","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"基准","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"-20~30%","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"-","type":"text"}]}]}]}]},{"type":"paragraph","content":[{"text":"推荐使用 32 位条件","type":"text","marks":[{"type":"strong"}]},{"text":":","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"PASS: 程序内存占用 \u003c 2GB","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"PASS: 不处理超大文件(\u003c 2GB)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"PASS: 目标用户是普通办公电脑","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"32 位编译方法","type":"text","marks":[{"type":"strong"}]},{"text":":","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# 1. 安装 32 位 Python(和 64 位可以共存)\n# 下载地址:https://www.python.org/downloads/windows/\n\n# 2. 用 32 位 Python 安装依赖\npy -3.12-32 -m pip install -r requirements.txt\n\n# 3. 用 32 位 Python 编译\npy -3.12-32 -m nuitka --standalone ...你的参数","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"二、模块排除清单(参考项目验证过的)","type":"text"}]},{"type":"paragraph","content":[{"text":"安全排除列表","type":"text","marks":[{"type":"strong"}]},{"text":"(运行时不需要):","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":""},"content":[{"text":"unittest,test,pytest,_pytest,doctest,pdb,pdbpp,\nsetuptools,pip,distutils,pkg_resources,\nemail.mime,http.server,xmlrpc,pydoc","type":"text"}]},{"type":"paragraph","content":[{"text":"预期效果","type":"text","marks":[{"type":"strong"}]},{"text":":节省 ","type":"text"},{"text":"30-50 MB","type":"text","marks":[{"type":"strong"}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"三、GUI 框架专用优化","type":"text"}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"Tkinter 极限优化(推荐,最轻量)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"nuitka --standalone --windows-console-mode=disable ^\n --lto=yes ^\n --jobs=8 ^\n --enable-plugin=tk-inter ^\n --enable-plugin=anti-bloat ^\n --noinclude-pytest-mode=nofollow ^\n --noinclude-setuptools-mode=nofollow ^\n --nofollow-import-to=unittest,test,pytest,_pytest,doctest,pdb,pdbpp ^\n --nofollow-import-to=setuptools,pip,distutils,pkg_resources ^\n --nofollow-import-to=email.mime,http.server,xmlrpc,pydoc ^\n --python-flag=no_docstrings ^\n --output-dir=dist ^\n --windows-icon-from-ico=icon.ico ^\n --remove-output ^\n main.py","type":"text"}]},{"type":"paragraph","content":[{"text":"预期体积","type":"text","marks":[{"type":"strong"}]},{"text":":80-120 MB(优化后)","type":"text"}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"PyQt5 / PySide2 优化","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"nuitka --standalone --windows-console-mode=disable ^\n --lto=yes ^\n --jobs=8 ^\n --enable-plugin=pyqt5 ^\n --enable-plugin=anti-bloat ^\n --noinclude-pytest-mode=nofollow ^\n --noinclude-setuptools-mode=nofollow ^\n --nofollow-import-to=unittest,test,pytest,_pytest,doctest,pdb ^\n --nofollow-import-to=setuptools,pip,distutils,pkg_resources ^\n --nofollow-import-to=PyQt5.QtWebEngine,PyQt5.QtWebEngineWidgets ^\n --nofollow-import-to=PyQt5.Qt3D,PyQt5.QtCharts ^\n --python-flag=no_docstrings ^\n --include-qt-plugins=sensible,styles,platforms ^\n --output-dir=dist ^\n --windows-icon-from-ico=icon.ico ^\n --remove-output ^\n main.py","type":"text"}]},{"type":"paragraph","content":[{"text":"预期体积","type":"text","marks":[{"type":"strong"}]},{"text":":120-250 MB(优化后)","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"四、一键编译脚本模板","type":"text"}]},{"type":"paragraph","content":[{"text":"保存为 ","type":"text","marks":[{"type":"strong"}]},{"text":"build_optimized.bat","type":"text","marks":[{"type":"code_inline"},{"type":"strong"}]},{"text":"(项目根目录)","type":"text","marks":[{"type":"strong"}]},{"text":":","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"batch"},"content":[{"text":"@echo off\nchcp 65001 >nul\nsetlocal enabledelayedexpansion\n\necho ========================================\necho Nuitka 极限优化编译(参考 参考项目)\necho ========================================\n\nREM === 配置区域(请修改为你的实际值) ===\nset APP_NAME=你的软件名\nset MAIN_FILE=main.py\nset ICON_FILE=icon.ico\n\nREM === 自动检测 CPU 核心数 ===\nREM 用 Windows 自带环境变量(wmic 在 Win11 22H2+ 已移除,探不到会让 --jobs=0 单线程编译)\nset CPU_CORES=%NUMBER_OF_PROCESSORS%\nif not defined CPU_CORES set CPU_CORES=4\nset /a BUILD_JOBS=%CPU_CORES%\n\nREM === 参考项目的模块排除清单 ===\nset EXCLUDE_MODULES=unittest,test,pytest,_pytest,doctest,pdb,pdbpp\nset EXCLUDE_MODULES=%EXCLUDE_MODULES%,setuptools,pip,distutils,pkg_resources\nset EXCLUDE_MODULES=%EXCLUDE_MODULES%,email.mime,http.server,xmlrpc,pydoc\n\necho.\necho [1/4] 清理旧编译...\nif exist dist rd /s /q dist\nif exist build rd /s /q build\n\necho.\necho [2/4] Nuitka 编译中(应用 参考项目优化策略)...\necho - CPU 核心: %CPU_CORES% (使用 %BUILD_JOBS% 线程)\necho - 模块排除: %EXCLUDE_MODULES%\necho.\n\nnuitka --standalone ^\n --windows-console-mode=disable ^\n --lto=yes ^\n --jobs=%BUILD_JOBS% ^\n --enable-plugin=anti-bloat ^\n --enable-plugin=tk-inter ^\n --noinclude-pytest-mode=nofollow ^\n --noinclude-setuptools-mode=nofollow ^\n --nofollow-import-to=%EXCLUDE_MODULES% ^\n --python-flag=no_docstrings ^\n --output-dir=dist ^\n --windows-icon-from-ico=%ICON_FILE% ^\n --remove-output ^\n %MAIN_FILE%\n\nif %errorlevel% neq 0 (\n echo.\n echo [错误] 编译失败!\n pause\n exit /b 1\n)\n\necho.\necho [3/4] 统计编译结果...\nfor /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\nset TOTAL_SIZE=%TOTAL_SIZE:,=%\nset /a SIZE_MB=%TOTAL_SIZE% / 1048576\necho - 编译后体积: %SIZE_MB% MB\n\necho.\necho [4/4] 执行瘦身清理(参考 参考项目策略)...\npowershell -ExecutionPolicy Bypass -File slim_dist.ps1 -DistPath \"dist\\%APP_NAME%.dist\"\n\necho.\necho ========================================\necho 编译完成!\necho ========================================\npause","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"五、dist 瘦身脚本(参考项目级别清理)","type":"text"}]},{"type":"paragraph","content":[{"text":"保存为 ","type":"text","marks":[{"type":"strong"}]},{"text":"slim_dist.ps1","type":"text","marks":[{"type":"code_inline"},{"type":"strong"}]},{"text":"(和 build_optimized.bat 同目录)","type":"text","marks":[{"type":"strong"}]},{"text":":","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"param(\n [string]$DistPath\n)\n\n$ErrorActionPreference = \"Continue\" # 不静默吞错:删除失败会显示出来,避免假成功\n\nWrite-Host \"`n========================================\" -ForegroundColor Cyan\nWrite-Host \"dist 瘦身清理(参考 参考项目策略)\" -ForegroundColor Cyan\nWrite-Host \"========================================\" -ForegroundColor Cyan\n\nif (-not (Test-Path $DistPath)) {\n Write-Host \"[错误] 找不到目录: $DistPath\" -ForegroundColor Red\n exit 1\n}\n\n# 统计初始体积\n$InitialSize = (Get-ChildItem -Path $DistPath -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1MB\nWrite-Host \"`n初始体积: $([math]::Round($InitialSize, 2)) MB\" -ForegroundColor Yellow\n\n# 参考项目特征:没有 .pdb, .pyi, __pycache__, test 等\nWrite-Host \"`n[应用 参考项目的清理策略...]\" -ForegroundColor Green\n\n# 1. 删除调试符号\nWrite-Host \"`n[1/7] 删除 .pdb 调试符号...\" -ForegroundColor Green\n$pdbFiles = Get-ChildItem -Path $DistPath -Recurse -Include *.pdb -File\n$pdbSize = ($pdbFiles | Measure-Object -Property Length -Sum).Sum / 1MB\nif ($pdbFiles.Count -gt 0) {\n $pdbFiles | Remove-Item -Force\n Write-Host \" 删除 $($pdbFiles.Count) 个文件,节省 $([math]::Round($pdbSize, 2)) MB\"\n} else {\n Write-Host \" 未发现 .pdb 文件(已优化)\" -ForegroundColor Gray\n}\n\n# 2. 删除类型提示\nWrite-Host \"`n[2/7] 删除 .pyi 类型提示...\" -ForegroundColor Green\n$pyiFiles = Get-ChildItem -Path $DistPath -Recurse -Include *.pyi -File\n$pyiSize = ($pyiFiles | Measure-Object -Property Length -Sum).Sum / 1MB\nif ($pyiFiles.Count -gt 0) {\n $pyiFiles | Remove-Item -Force\n Write-Host \" 删除 $($pyiFiles.Count) 个文件,节省 $([math]::Round($pyiSize, 2)) MB\"\n} else {\n Write-Host \" 未发现 .pyi 文件(已优化)\" -ForegroundColor Gray\n}\n\n# 3. 删除 __pycache__\nWrite-Host \"`n[3/7] 删除 __pycache__ 缓存...\" -ForegroundColor Green\n$pycacheDirs = Get-ChildItem -Path $DistPath -Recurse -Directory -Filter \"__pycache__\"\n$pycacheSize = 0\nforeach ($dir in $pycacheDirs) {\n $size = (Get-ChildItem -Path $dir.FullName -Recurse -File | Measure-Object -Property Length -Sum).Sum\n $pycacheSize += $size\n Remove-Item -Path $dir.FullName -Recurse -Force\n}\nif ($pycacheDirs.Count -gt 0) {\n Write-Host \" 删除 $($pycacheDirs.Count) 个目录,节省 $([math]::Round($pycacheSize / 1MB, 2)) MB\"\n} else {\n Write-Host \" 未发现 __pycache__(已优化)\" -ForegroundColor Gray\n}\n\n# 4. 删除测试目录\nWrite-Host \"`n[4/7] 删除 test/tests 测试目录...\" -ForegroundColor Green\n$testDirs = Get-ChildItem -Path $DistPath -Recurse -Directory | Where-Object { $_.Name -match '^tests?

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 - folder slimming, DLL footprint analysis, 32-bit vs 64-bit size tradeoffs - Inno Setup packa…

}\n$testSize = 0\nforeach ($dir in $testDirs) {\n $size = (Get-ChildItem -Path $dir.FullName -Recurse -File | Measure-Object -Property Length -Sum).Sum\n $testSize += $size\n Remove-Item -Path $dir.FullName -Recurse -Force\n}\nif ($testDirs.Count -gt 0) {\n Write-Host \" 删除 $($testDirs.Count) 个目录,节省 $([math]::Round($testSize / 1MB, 2)) MB\"\n} else {\n Write-Host \" 未发现测试目录(已优化)\" -ForegroundColor Gray\n}\n\n# 5. 删除文档和示例\nWrite-Host \"`n[5/7] 删除 docs/examples 文档目录...\" -ForegroundColor Green\n$docDirs = Get-ChildItem -Path $DistPath -Recurse -Directory | Where-Object { $_.Name -match '^(docs|examples|samples|demo)

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 - folder slimming, DLL footprint analysis, 32-bit vs 64-bit size tradeoffs - Inno Setup packa…

}\n$docSize = 0\nforeach ($dir in $docDirs) {\n $size = (Get-ChildItem -Path $dir.FullName -Recurse -File | Measure-Object -Property Length -Sum).Sum\n $docSize += $size\n Remove-Item -Path $dir.FullName -Recurse -Force\n}\nif ($docDirs.Count -gt 0) {\n Write-Host \" 删除 $($docDirs.Count) 个目录,节省 $([math]::Round($docSize / 1MB, 2)) MB\"\n} else {\n Write-Host \" 未发现文档目录(已优化)\" -ForegroundColor Gray\n}\n\n# 6. 删除 .pyc 文件\nWrite-Host \"`n[6/7] 删除 .pyc 字节码...\" -ForegroundColor Green\n$pycFiles = Get-ChildItem -Path $DistPath -Recurse -Include *.pyc -File\n$pycSize = ($pycFiles | Measure-Object -Property Length -Sum).Sum / 1MB\nif ($pycFiles.Count -gt 0) {\n $pycFiles | Remove-Item -Force\n Write-Host \" 删除 $($pycFiles.Count) 个文件,节省 $([math]::Round($pycSize, 2)) MB\"\n} else {\n Write-Host \" 未发现 .pyc 文件(已优化)\" -ForegroundColor Gray\n}\n\n# 7. 精简 .dist-info 元数据\nWrite-Host \"`n[7/7] 精简 .dist-info 元数据...\" -ForegroundColor Green\n$distInfoDirs = Get-ChildItem -Path $DistPath -Recurse -Directory -Filter \"*.dist-info\"\n$removedCount = 0\n$removedSize = 0\nforeach ($infoDir in $distInfoDirs) {\n # 仅删安装期记账文件;保留 METADATA 与 entry_points.txt(运行期被 importlib.metadata 读取,删除会破坏插件发现)\n $filesToRemove = @(\"RECORD\", \"INSTALLER\", \"direct_url.json\")\n foreach ($fileName in $filesToRemove) {\n $file = Join-Path $infoDir.FullName $fileName\n if (Test-Path $file) {\n $size = (Get-Item $file).Length\n $removedSize += $size\n Remove-Item $file -Force\n $removedCount++\n }\n }\n}\nif ($removedCount -gt 0) {\n Write-Host \" 删除 $removedCount 个元数据文件,节省 $([math]::Round($removedSize / 1MB, 2)) MB\"\n} else {\n Write-Host \" 未发现可清理的元数据(已优化)\" -ForegroundColor Gray\n}\n\n# 统计最终体积\n$FinalSize = (Get-ChildItem -Path $DistPath -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1MB\n$SavedSize = $InitialSize - $FinalSize\n$SavedPercent = if ($InitialSize -gt 0) { ($SavedSize / $InitialSize) * 100 } else { 0 }\n\nWrite-Host \"`n========================================\" -ForegroundColor Cyan\nWrite-Host \"清理完成!\" -ForegroundColor Green\nWrite-Host \"========================================\" -ForegroundColor Cyan\nWrite-Host \"初始体积: $([math]::Round($InitialSize, 2)) MB\" -ForegroundColor Yellow\nWrite-Host \"最终体积: $([math]::Round($FinalSize, 2)) MB\" -ForegroundColor Green\nWrite-Host \"节省空间: $([math]::Round($SavedSize, 2)) MB ($([math]::Round($SavedPercent, 1))%)\" -ForegroundColor Cyan\nWrite-Host \"========================================`n\" -ForegroundColor Cyan\n\n# 对比 参考项目\nWrite-Host \"[对比参考]\" -ForegroundColor Yellow\nWrite-Host \"参考项目总体积: 323 MB (包含 PyQt, OpenCV, Playwright 等重量级库)\" -ForegroundColor Gray\nWrite-Host \"如果你的项目是纯 Tkinter + 标准库,目标应该在 80-150 MB\" -ForegroundColor Gray","type":"text"}]},{"type":"paragraph","content":[{"text":"预期效果","type":"text","marks":[{"type":"strong"}]},{"text":":节省 ","type":"text"},{"text":"15-30%","type":"text","marks":[{"type":"strong"}]},{"text":" 体积","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"六、DLL 依赖分析工具","type":"text"}]},{"type":"paragraph","content":[{"text":"保存为 ","type":"text","marks":[{"type":"strong"}]},{"text":"analyze_dlls.py","type":"text","marks":[{"type":"code_inline"},{"type":"strong"}]},{"text":"(用于找出体积大户)","type":"text","marks":[{"type":"strong"}]},{"text":":","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"\"\"\"\nDLL 依赖分析工具\n参考 参考项目的 DLL 管理策略,帮助识别体积大户和优化建议\n\"\"\"\nimport sys\nfrom pathlib import Path\n\ndef analyze_dlls(dist_path: str):\n \"\"\"分析 dist 目录中的 DLL 依赖\"\"\"\n dist_dir = Path(dist_path)\n\n if not dist_dir.exists():\n print(f\"[错误] 目录不存在: {dist_path}\")\n return\n\n print(\"=\" * 70)\n print(\"DLL 依赖分析(参考 参考项目策略)\")\n print(\"=\" * 70)\n\n # 收集所有 DLL\n dll_files = list(dist_dir.rglob(\"*.dll\"))\n\n if not dll_files:\n print(\"\\n未发现 DLL 文件\")\n return\n\n # 按大小排序\n dll_data = [(dll, dll.stat().st_size) for dll in dll_files]\n dll_data.sort(key=lambda x: x[1], reverse=True)\n\n total_size = sum(size for _, size in dll_data)\n\n print(f\"\\n总 DLL 数量: {len(dll_files)}\")\n print(f\"总 DLL 体积: {total_size / 1024 / 1024:.2f} MB\\n\")\n\n # 参考项目对比\n print(\"[对比参考] 参考项目的 DLL 情况:\")\n print(\" - 总数量: 71 个\")\n print(\" - 总体积: 93.23 MB\")\n print(\" - 最大的: libopenblas (26.85 MB), opengl32sw (15.25 MB)\\n\")\n\n # 分析大于 3MB 的 DLL\n large_dlls = [(dll, size) for dll, size in dll_data if size > 3 * 1024 * 1024]\n\n if large_dlls:\n print(\"=\" * 70)\n print(\"WARNING: 大于 3MB 的 DLL(需重点关注)\")\n print(\"=\" * 70)\n\n for dll, size in large_dlls:\n size_mb = size / 1024 / 1024\n relative_path = dll.relative_to(dist_dir)\n name_lower = dll.name.lower()\n\n print(f\"\\n{size_mb:8.2f} MB {dll.name}\")\n print(f\" 位置: {relative_path.parent}\")\n\n # 优化建议\n suggestions = get_optimization_suggestion(name_lower)\n if suggestions:\n for suggestion in suggestions:\n print(f\" {suggestion}\")\n\n # 检查冗余 DLL\n print(\"\\n\" + \"=\" * 70)\n print(\" 冗余检查\")\n print(\"=\" * 70)\n\n # 检查调试版本\n debug_dlls = [dll for dll, _ in dll_data if dll.stem.endswith('d')]\n if debug_dlls:\n print(f\"\\nWARNING: 发现 {len(debug_dlls)} 个调试版本 DLL(可以删除):\")\n for dll in debug_dlls:\n print(f\" - {dll.name}\")\n else:\n print(\"\\nPASS: 未发现调试版本 DLL(已优化)\")\n\n # VC++ Runtime\n vc_runtimes = [dll for dll, _ in dll_data if 'vcruntime' in dll.name.lower() or 'msvcp' in dll.name.lower()]\n if vc_runtimes:\n print(f\"\\n[VC++ Runtime 库] 发现 {len(vc_runtimes)} 个:\")\n for dll in vc_runtimes:\n size_mb = dll.stat().st_size / 1024 / 1024\n print(f\" - {dll.name} ({size_mb:.2f} MB)\")\n print(\" 这些是必需的,参考项目也包含了这些文件\")\n\n # 全部 DLL 列表\n print(\"\\n\" + \"=\" * 70)\n print(\" 完整 DLL 列表(按体积排序,前 20)\")\n print(\"=\" * 70)\n print(f\"\\n{'体积 (MB)':>10} {'文件名':\u003c30} 位置\")\n print(\"-\" * 70)\n\n for dll, size in dll_data[:20]:\n size_mb = size / 1024 / 1024\n relative_path = dll.relative_to(dist_dir)\n location = str(relative_path.parent) if relative_path.parent != Path('.') else \"根目录\"\n print(f\"{size_mb:10.2f} {dll.name:\u003c30} {location}\")\n\n if len(dll_data) > 20:\n remaining_size = sum(size for _, size in dll_data[20:]) / 1024 / 1024\n print(f\"... 还有 {len(dll_data) - 20} 个 DLL,共 {remaining_size:.2f} MB\")\n\n\ndef get_optimization_suggestion(dll_name: str) -> list:\n \"\"\"根据 DLL 名称给出优化建议\"\"\"\n suggestions = []\n\n if \"openblas\" in dll_name or \"mkl\" in dll_name:\n suggestions.append(\"数学运算库,参考项目的 libopenblas 有 26.85 MB\")\n suggestions.append(\"如不需要高性能计算可考虑轻量版\")\n\n elif \"opencv\" in dll_name or \"ffmpeg\" in dll_name:\n suggestions.append(\"OpenCV 相关,参考项目的 opencv_videoio_ffmpeg 有 18.48 MB\")\n suggestions.append(\"考虑用 opencv-python-headless\")\n\n elif \"qt5\" in dll_name or \"qt6\" in dll_name or \"pyside\" in dll_name:\n suggestions.append(\"Qt 库,参考项目的 Qt5Core 有 5.13 MB\")\n suggestions.append(\"可排除不需要的模块(WebEngine, 3D, Charts)\")\n\n elif \"opengl\" in dll_name and \"sw\" in dll_name:\n suggestions.append(\"OpenGL 软件渲染器,参考项目保留了 15.25 MB\")\n suggestions.append(\"通常可以删除(使用硬件渲染)\")\n\n elif \"d3dcompiler\" in dll_name:\n suggestions.append(\"DirectX 编译器,参考项目有 3.53 MB\")\n\n elif \"mfc140\" in dll_name:\n suggestions.append(\"MFC 库,参考项目有 4.89 MB\")\n\n return suggestions\n\n\nif __name__ == \"__main__\":\n if len(sys.argv) \u003c 2:\n print(\"用法: python analyze_dlls.py \u003cdist目录路径>\")\n print(\"示例: python analyze_dlls.py dist/main.dist\")\n sys.exit(1)\n\n analyze_dlls(sys.argv[1])","type":"text"}]},{"type":"paragraph","content":[{"text":"使用方法","type":"text","marks":[{"type":"strong"}]},{"text":":","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python analyze_dlls.py dist/你的软件名.dist","type":"text"}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"完整优化工作流","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"步骤 1:修改编译脚本配置","type":"text"}]},{"type":"paragraph","content":[{"text":"编辑 ","type":"text"},{"text":"build_optimized.bat","type":"text","marks":[{"type":"code_inline"}]},{"text":",修改这 3 行:","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"batch"},"content":[{"text":"set APP_NAME=你的软件名 REM 改成实际名称\nset MAIN_FILE=main.py REM 你的主程序文件\nset ICON_FILE=icon.ico REM 你的图标文件","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"步骤 2:一键编译+瘦身","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# 在项目根目录执行\nbuild_optimized.bat","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"步骤 3:分析 DLL 依赖","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python analyze_dlls.py dist/你的软件名.dist","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"步骤 4:根据分析结果优化","type":"text"}]},{"type":"paragraph","content":[{"text":"如果用了 OpenCV","type":"text","marks":[{"type":"strong"}]},{"text":" → 改用无头版","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"pip uninstall opencv-python\npip install opencv-python-headless","type":"text"}]},{"type":"paragraph","content":[{"text":"如果用了 Qt","type":"text","marks":[{"type":"strong"}]},{"text":" → 排除不需要的模块","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"batch"},"content":[{"text":"# 在编译命令中添加\n--nofollow-import-to=PyQt5.QtWebEngine,PyQt5.Qt3D,PyQt5.QtCharts","type":"text"}]},{"type":"paragraph","content":[{"text":"删除软件渲染器","type":"text","marks":[{"type":"strong"}]},{"text":"(如果不需要)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"# 在 dist 目录执行\nRemove-Item \"opengl32sw.dll\" -Force","type":"text"}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"VC++ 运行库处理方案","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"方案一:静态链接(推荐)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"nuitka --static-libpython=yes ...","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"方案二:捆绑运行库安装(商业发布推荐)","type":"text"}]},{"type":"paragraph","content":[{"text":"在 Inno Setup 脚本中添加:","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"iss"},"content":[{"text":"; WARNING: VC++ 运行库架构必须与 Python/Nuitka 构建架构一致。\n; 本 skill 推荐 32 位 Python,故默认捆绑 vc_redist.x86.exe;\n; 若用 64 位 Python 编译,请把下面两处改为 vc_redist.x64.exe。\n[Files]\nSource: \"{#MySourceDir}\\..\\vc_redist.x86.exe\"; DestDir: \"{tmp}\"; Flags: deleteafterinstall\n\n[Run]\nFilename: \"{tmp}\\vc_redist.x86.exe\"; Parameters: \"/quiet /norestart\"; StatusMsg: \"正在安装运行库...\"; Flags: waituntilterminated","type":"text"}]},{"type":"blockquote","content":[{"type":"paragraph","content":[{"text":"下载地址:","type":"text"},{"text":"Microsoft Visual C++ Redistributable","type":"text","marks":[{"type":"link","attrs":{"href":"https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist","title":null}}]}]}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"Inno Setup 脚本模板(商业终极版)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"iss"},"content":[{"text":"; =====================================================================\n; WARNING: 商业级 Python 安装脚本 (Inno Setup 6.x)\n; 特性:LZMA2 极限压缩 | 全中文 | 完整元数据 | 无残留卸载\n; 参考:参考项目(323 MB, LZMA2 压缩)\n; =====================================================================\n\n; --- 1. 参数定义 ---\n#define MyAppName \"{{APP_NAME}}\"\n#define MyAppVersion \"{{APP_VERSION}}\"\n#define MyAppPublisher \"{{PUBLISHER}}\"\n#define MyAppURL \"{{APP_URL}}\"\n#define MyAppExeName \"{{EXE_NAME}}\"\n#define MySourceDir \"{{SOURCE_DIR}}\"\n#define MyOutputDir \"{{OUTPUT_DIR}}\"\n;#define MyIconPath \"{{ICON_PATH}}\"\n\n[Setup]\n; --- 身份识别 ---\nAppId={{GENERATE_RANDOM_GUID}}\nAppName={#MyAppName}\nAppVersion={#MyAppVersion}\nAppPublisher={#MyAppPublisher}\nAppPublisherURL={#MyAppURL}\nAppSupportURL={#MyAppURL}\nAppUpdatesURL={#MyAppURL}\n\n; --- 安装路径与权限 ---\nDefaultDirName={autopf}\\{#MyAppName}\nDefaultGroupName={#MyAppName}\nDisableDirPage=no\nDisableProgramGroupPage=no\nPrivilegesRequired=admin\n\n; --- 输出设置 ---\nOutputDir={#MyOutputDir}\nOutputBaseFilename=Setup_{#MyAppName}_v{#MyAppVersion}\n\n; --- 视觉体验 ---\nWizardStyle=modern\n#ifdef MyIconPath\nSetupIconFile={#MyIconPath}\nUninstallDisplayIcon={app}\\{#MyAppExeName}\n#endif\n\n; --- 核心压缩 (参考 参考项目) ---\nCompression=lzma2/ultra64\nSolidCompression=yes\nLZMAUseSeparateProcess=yes\n\n; --- 架构 ---\n; 注意:仅 64 位 Python 构建才设此项。本 skill 推荐 32 位 Python——\n; 32 位构建请保持注释,使应用按 32 位安装并与上面捆绑的 vc_redist.x86.exe 匹配。\n; 仅当用 64 位 Python 编译时才取消注释。\n;ArchitecturesInstallIn64BitMode=x64compatible\n\n[Languages]\nName: \"chinesesimplified\"; MessagesFile: \"compiler:Languages\\ChineseSimplified.isl\"\n\n[Files]\nSource: \"{#MySourceDir}\\*\"; DestDir: \"{app}\"; Flags: ignoreversion recursesubdirs createallsubdirs\n\n[UninstallDelete]\nType: filesandordirs; Name: \"{app}\\*\"\n\n[Icons]\nName: \"{autodesktop}\\{#MyAppName}\"; Filename: \"{app}\\{#MyAppExeName}\"; Tasks: desktopicon\nName: \"{group}\\{#MyAppName}\"; Filename: \"{app}\\{#MyAppExeName}\"\nName: \"{group}\\卸载 {#MyAppName}\"; Filename: \"{uninstallexe}\"\n\n[Tasks]\nName: \"desktopicon\"; Description: \"{cm:CreateDesktopIcon}\"; GroupDescription: \"{cm:AdditionalIcons}\"; Flags: unchecked\n\n[Run]\nFilename: \"{app}\\{#MyAppExeName}\"; Description: \"{cm:LaunchProgram,{#MyAppName}}\"; Flags: nowait postinstall skipifsilent","type":"text"}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"占位符说明","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"占位符","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"说明","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"示例值","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"{{APP_NAME}}","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"软件显示名称","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"红墨批注","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"{{APP_VERSION}}","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"版本号","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"1.0.0","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"{{PUBLISHER}}","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"发布者/公司名","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"MyCompany","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"{{APP_URL}}","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"官网地址","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"https://example.com","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"{{EXE_NAME}}","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"主程序文件名","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"RedInk.exe","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"{{SOURCE_DIR}}","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Nuitka dist 文件夹路径","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"D:\\project\\dist\\RedInk.dist","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"{{OUTPUT_DIR}}","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"安装包输出路径","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"D:\\project\\output","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"{{ICON_PATH}}","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"图标文件路径","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"D:\\project\\icon.ico","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"{{GENERATE_RANDOM_GUID}}","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"需生成唯一GUID","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"使用 Inno Setup \"Tools > Generate GUID\"","type":"text"}]}]}]}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"常见问题 (FAQ)","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Q1: 安装后双击程序无反应?","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"打开 CMD,手动运行 exe 查看错误信息","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"检查是否缺少 VC++ 运行库","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"检查 Nuitka 编译是否成功","type":"text"}]}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Q2: 安装包体积过大?","type":"text"}]},{"type":"paragraph","content":[{"text":"优化方法","type":"text","marks":[{"type":"strong"}]},{"text":":","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"使用 32 位 Python 编译(节省 20-30%)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"应用 参考项目的模块排除清单","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"启用 Anti-Bloat 插件","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"执行 dist 文件夹瘦身脚本","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"分析 DLL,移除不必要的大文件","type":"text"}]}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Q3: 杀毒软件误报?","type":"text"}]},{"type":"paragraph","content":[{"text":"解决方案","type":"text","marks":[{"type":"strong"}]},{"text":":","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"提交到主流杀毒厂商进行白名单申请","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"购买代码签名证书(推荐:Sectigo, DigiCert)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"避免使用 UPX 压缩","type":"text"}]}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Q4: 安装时提示 Windows 已保护你的电脑?","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"购买 EV 代码签名证书(可立即获得信任)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"普通代码签名证书需要积累安装量后逐渐获得信任","type":"text"}]}]}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"实战问题处理记录(更新 2026-02-07)","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"安装后提示缺少 python3xx.dll","type":"text","marks":[{"type":"strong"}]},{"text":":必须使用 Nuitka ","type":"text"},{"text":"--standalone","type":"text","marks":[{"type":"code_inline"}]},{"text":";确认 dist 内存在该 dll;不要打单文件版。","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"安装后点击无反应","type":"text","marks":[{"type":"strong"}]},{"text":":GUI 启动期可能被重依赖阻塞;将重依赖延迟到\"开始导出\"再 import;添加日志排查。","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Nuitka + MinGW 在非 ASCII 路径报错","type":"text","marks":[{"type":"strong"}]},{"text":":把源码复制到 ASCII 目录再编译;设置 ","type":"text"},{"text":"PYTHONIOENCODING=utf-8","type":"text","marks":[{"type":"code_inline"}]},{"text":"。","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Inno Setup 警告 ","type":"text","marks":[{"type":"strong"}]},{"text":"x64","type":"text","marks":[{"type":"code_inline"},{"type":"strong"}]},{"text":" 已弃用(仅 64 位构建需要 64 位安装模式时)","type":"text","marks":[{"type":"strong"}]},{"text":":改为 ","type":"text"},{"text":"ArchitecturesInstallIn64BitMode=x64compatible","type":"text","marks":[{"type":"code_inline"}]},{"text":";32 位构建无需此项。","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"--disable-console","type":"text","marks":[{"type":"code_inline"},{"type":"strong"}]},{"text":" 已废弃","type":"text","marks":[{"type":"strong"}]},{"text":":改用 ","type":"text"},{"text":"--windows-console-mode=disable","type":"text","marks":[{"type":"code_inline"}]},{"text":"。","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"dist 出现 ","type":"text","marks":[{"type":"strong"}]},{"text":"_nuitka_temp.exe","type":"text","marks":[{"type":"code_inline"},{"type":"strong"}]},{"text":":在 [Files] 中排除它。","type":"text"}]}]}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"heading","attrs":{"level":2},"content":[{"text":"优化效果预期","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"优化组合","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"体积减少","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"启动提升","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"风险等级","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"基础编译","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"基准","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"基准","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"无","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"+ ","type":"text"},{"text":"--lto=yes","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"5-10%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"10-20%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"PASS: 无","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"+ anti-bloat","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"15-25%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"-","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"PASS: 无","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"+ 模块排除","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"20-35%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"5%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"PASS: 无","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"+ dist 瘦身","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"25-40%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"-","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"PASS: 无","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"+ 32 位编译","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"40-60%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"-","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"PASS: 无","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"全部组合","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"45-65%","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"15-25%","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"PASS: ","type":"text"},{"text":"无风险","type":"text","marks":[{"type":"strong"}]}]}]}]}]},{"type":"blockquote","content":[{"type":"paragraph","content":[{"text":"WARNING: ","type":"text"},{"text":"不建议使用 UPX 压缩","type":"text","marks":[{"type":"strong"}]},{"text":",虽然能进一步减小体积,但极易触发杀毒软件误报。","type":"text"}]}]},{"type":"hr","attrs":{"markup":"---"}},{"type":"paragraph","content":[{"text":"基于 参考项目实战经验优化,助你打造商业级安装包!","type":"text","marks":[{"type":"strong"}]}]}]},"metadata":{"date":"2026-11-02","name":"generating-python-installer","author":"@skillopedia","source":{"stars":295436,"repo_name":"ECC","origin_url":"https://github.com/affaan-m/ECC/blob/HEAD/skills/generating-python-installer/SKILL.md","repo_owner":"affaan-m","body_sha256":"47e73ef601d900be3b5ccb5d1a1ba2371d3e46c67b5243c1810e51cd2d8f62f3","cluster_key":"a8513feb209dd69d40b001f557e09119dcba76f8542114aa37d77be41d25802f","clean_bundle":{"format":"clean-skill-bundle-v1","source":"affaan-m/ECC/skills/generating-python-installer/SKILL.md","text_bytes":0,"source_commit":"b38be6a7f6350964d59328b52f0624e1d1d552d1","skills_sh_rank":4330,"attachment_count":0,"text_attachments":0,"attachment_storage":"skill_attachments","binary_attachments":0},"cluster_size":1,"skill_md_path":"skills/generating-python-installer/SKILL.md","import_metadata":{"date":"2026-11-02","author":"@skillopedia","version":"v1","category":"software-engineering","category_label":"Engineering"},"exact_dupes_collapsed_into_this":0},"version":"v1","category":"software-engineering","import_tag":"skills-sh-top20k-2026-11","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 when a Python app must ship as a minimal, fast-starting Windows installer; not for basic script-to-exe conversion. 中文触发:Nuitka 极限优化、Python 商业打包、极限编译 Python、dist 瘦身、DLL 分析、最小安装包、最快启动、商业级打包风格"}},"renderedAt":1793670896456}

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 - folder slimming, DLL footprint analysis, 32-bit vs 64-bit size tradeoffs - Inno Setup packa…