Loading...
Loading...
Compare original and translation side by side
distdistdistdistdistopencv-python-headlessopengl32swdistdistopencv-python-headlessopengl32swdist| 组件 | 体积 | 占比 | 优化建议 |
|---|---|---|---|
| playwright | 76.74 MB | 23.8% | 非必要可移除 |
| OpenCV | 62.38 MB | 19.3% | 用 opencv-python-headless |
| PySide2 | 22.52 MB | 7.0% | 排除 WebEngine/3D/Charts |
| 其他依赖 | 161.36 MB | 49.9% | - |
| 组件 | 体积 | 占比 | 优化建议 |
|---|---|---|---|
| playwright | 76.74 MB | 23.8% | 非必要可移除 |
| OpenCV | 62.38 MB | 19.3% | 用 opencv-python-headless |
| PySide2 | 22.52 MB | 7.0% | 排除 WebEngine/3D/Charts |
| 其他依赖 | 161.36 MB | 49.9% | - |
| 项目类型 | Nuitka 原始 | 优化后 | 参考项目实测 |
|---|---|---|---|
| Tkinter + 标准库 | 150-250 MB | 80-120 MB | - |
| PyQt/PySide | 200-400 MB | 120-250 MB | 323 MB (含 OpenCV 等) |
| 含 numpy/pandas | 300-600 MB | 180-350 MB | - |
| 项目类型 | Nuitka 原始 | 优化后 | 参考项目实测 |
|---|---|---|---|
| Tkinter + 标准库 | 150-250 MB | 80-120 MB | - |
| PyQt/PySide | 200-400 MB | 120-250 MB | 323 MB (含 OpenCV 等) |
| 含 numpy/pandas | 300-600 MB | 180-350 MB | - |
WARNING: 重要规则:以下所有参数必须逐一向用户确认,禁止自动填充或使用默认值!
| 参数 | 说明 | 示例 |
|---|---|---|
| 软件名称 (App Name) | 软件显示名称 | |
| 版本号 (Version) | 语义化版本号 | |
| 发布者/公司名 (Publisher) | 控制面板显示的发布者 | |
| 主程序 (Exe Name) | 主可执行文件名 | |
| 源路径 (Source Dir) | Nuitka dist 文件夹绝对路径 | |
| 输出路径 (Output Dir) | 安装包生成位置 | |
| 图标路径 (Icon Path) | .ico 文件绝对路径(可选但推荐) | |
| 官网地址 (URL) | 可选,用于控制面板链接 | |
"请提供以下打包参数,我需要您逐一确认:
- 软件名称:
- 版本号:
- 发布者/公司名:
- 主程序文件名(如 xxx.exe):
- 源路径(Nuitka dist 文件夹):
- 输出路径(安装包保存位置):
- 图标路径(.ico 文件,可留空):
- 官网地址(可留空):
请逐一填写,或回复"跳过"表示使用空值。"
"WARNING: 编译参数检查:
- 去黑窗:请确认您的 dist 文件夹是使用
编译的。(否则安装后依然会有黑框)nuitka --windows-console-mode=disable- 高性能:请确认是否使用了
。(否则启动速度可能不理想)--lto=yes- 运行库:请确保 dist 文件夹内已包含必要的 VC++ 运行库,防止在纯净系统上无法运行。
确认源文件已准备好请回复"确认",否则请先重新编译。"
WARNING: 重要规则:以下所有参数必须逐一向用户确认,禁止自动填充或使用默认值!
| 参数 | 说明 | 示例 |
|---|---|---|
| 软件名称 (App Name) | 软件显示名称 | |
| 版本号 (Version) | 语义化版本号 | |
| 发布者/公司名 (Publisher) | 控制面板显示的发布者 | |
| 主程序 (Exe Name) | 主可执行文件名 | |
| 源路径 (Source Dir) | Nuitka dist 文件夹绝对路径 | |
| 输出路径 (Output Dir) | 安装包生成位置 | |
| 图标路径 (Icon Path) | .ico 文件绝对路径(可选但推荐) | |
| 官网地址 (URL) | 可选,用于控制面板链接 | |
"请提供以下打包参数,我需要您逐一确认:
- 软件名称:
- 版本号:
- 发布者/公司名:
- 主程序文件名(如 xxx.exe):
- 源路径(Nuitka dist 文件夹):
- 输出路径(安装包保存位置):
- 图标路径(.ico 文件,可留空):
- 官网地址(可留空):
请逐一填写,或回复"跳过"表示使用空值。"
"WARNING: 编译参数检查:
- 去黑窗:请确认您的 dist 文件夹是使用
编译的。(否则安装后依然会有黑框)nuitka --windows-console-mode=disable- 高性能:请确认是否使用了
。(否则启动速度可能不理想)--lto=yes- 运行库:请确保 dist 文件夹内已包含必要的 VC++ 运行库,防止在纯净系统上无法运行。
确认源文件已准备好请回复"确认",否则请先重新编译。"
| 组件 | 64位体积 | 32位体积 | 节省 |
|---|---|---|---|
| python3x.dll | ~4.5 MB | ~3.8 MB | 15% |
| Qt5Core.dll | ~8 MB | ~5 MB | 37% |
| numpy | ~30 MB | ~20 MB | 33% |
| 总体 | 基准 | -20~30% | - |
undefined| 组件 | 64位体积 | 32位体积 | 节省 |
|---|---|---|---|
| python3x.dll | ~4.5 MB | ~3.8 MB | 15% |
| Qt5Core.dll | ~8 MB | ~5 MB | 37% |
| numpy | ~30 MB | ~20 MB | 33% |
| 总体 | 基准 | -20~30% | - |
undefinedundefinedundefinedunittest,test,pytest,_pytest,doctest,pdb,pdbpp,
setuptools,pip,distutils,pkg_resources,
email.mime,http.server,xmlrpc,pydocunittest,test,pytest,_pytest,doctest,pdb,pdbpp,
setuptools,pip,distutils,pkg_resources,
email.mime,http.server,xmlrpc,pydocnuitka --standalone --windows-console-mode=disable ^
--lto=yes ^
--jobs=8 ^
--enable-plugin=tk-inter ^
--enable-plugin=anti-bloat ^
--noinclude-pytest-mode=nofollow ^
--noinclude-setuptools-mode=nofollow ^
--nofollow-import-to=unittest,test,pytest,_pytest,doctest,pdb,pdbpp ^
--nofollow-import-to=setuptools,pip,distutils,pkg_resources ^
--nofollow-import-to=email.mime,http.server,xmlrpc,pydoc ^
--python-flag=no_docstrings ^
--output-dir=dist ^
--windows-icon-from-ico=icon.ico ^
--remove-output ^
main.pynuitka --standalone --windows-console-mode=disable ^
--lto=yes ^
--jobs=8 ^
--enable-plugin=tk-inter ^
--enable-plugin=anti-bloat ^
--noinclude-pytest-mode=nofollow ^
--noinclude-setuptools-mode=nofollow ^
--nofollow-import-to=unittest,test,pytest,_pytest,doctest,pdb,pdbpp ^
--nofollow-import-to=setuptools,pip,distutils,pkg_resources ^
--nofollow-import-to=email.mime,http.server,xmlrpc,pydoc ^
--python-flag=no_docstrings ^
--output-dir=dist ^
--windows-icon-from-ico=icon.ico ^
--remove-output ^
main.pynuitka --standalone --windows-console-mode=disable ^
--lto=yes ^
--jobs=8 ^
--enable-plugin=pyqt5 ^
--enable-plugin=anti-bloat ^
--noinclude-pytest-mode=nofollow ^
--noinclude-setuptools-mode=nofollow ^
--nofollow-import-to=unittest,test,pytest,_pytest,doctest,pdb ^
--nofollow-import-to=setuptools,pip,distutils,pkg_resources ^
--nofollow-import-to=PyQt5.QtWebEngine,PyQt5.QtWebEngineWidgets ^
--nofollow-import-to=PyQt5.Qt3D,PyQt5.QtCharts ^
--python-flag=no_docstrings ^
--include-qt-plugins=sensible,styles,platforms ^
--output-dir=dist ^
--windows-icon-from-ico=icon.ico ^
--remove-output ^
main.pynuitka --standalone --windows-console-mode=disable ^
--lto=yes ^
--jobs=8 ^
--enable-plugin=pyqt5 ^
--enable-plugin=anti-bloat ^
--noinclude-pytest-mode=nofollow ^
--noinclude-setuptools-mode=nofollow ^
--nofollow-import-to=unittest,test,pytest,_pytest,doctest,pdb ^
--nofollow-import-to=setuptools,pip,distutils,pkg_resources ^
--nofollow-import-to=PyQt5.QtWebEngine,PyQt5.QtWebEngineWidgets ^
--nofollow-import-to=PyQt5.Qt3D,PyQt5.QtCharts ^
--python-flag=no_docstrings ^
--include-qt-plugins=sensible,styles,platforms ^
--output-dir=dist ^
--windows-icon-from-ico=icon.ico ^
--remove-output ^
main.pybuild_optimized.bat@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
echo ========================================
echo Nuitka 极限优化编译(参考 参考项目)
echo ========================================
REM === 配置区域(请修改为你的实际值) ===
set APP_NAME=你的软件名
set MAIN_FILE=main.py
set ICON_FILE=icon.ico
REM === 自动检测 CPU 核心数 ===
REM 用 Windows 自带环境变量(wmic 在 Win11 22H2+ 已移除,探不到会让 --jobs=0 单线程编译)
set CPU_CORES=%NUMBER_OF_PROCESSORS%
if not defined CPU_CORES set CPU_CORES=4
set /a BUILD_JOBS=%CPU_CORES%
REM === 参考项目的模块排除清单 ===
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%,email.mime,http.server,xmlrpc,pydoc
echo.
echo [1/4] 清理旧编译...
if exist dist rd /s /q dist
if exist build rd /s /q build
echo.
echo [2/4] Nuitka 编译中(应用 参考项目优化策略)...
echo - CPU 核心: %CPU_CORES% (使用 %BUILD_JOBS% 线程)
echo - 模块排除: %EXCLUDE_MODULES%
echo.
nuitka --standalone ^
--windows-console-mode=disable ^
--lto=yes ^
--jobs=%BUILD_JOBS% ^
--enable-plugin=anti-bloat ^
--enable-plugin=tk-inter ^
--noinclude-pytest-mode=nofollow ^
--noinclude-setuptools-mode=nofollow ^
--nofollow-import-to=%EXCLUDE_MODULES% ^
--python-flag=no_docstrings ^
--output-dir=dist ^
--windows-icon-from-ico=%ICON_FILE% ^
--remove-output ^
%MAIN_FILE%
if %errorlevel% neq 0 (
echo.
echo [错误] 编译失败!
pause
exit /b 1
)
echo.
echo [3/4] 统计编译结果...
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 /a SIZE_MB=%TOTAL_SIZE% / 1048576
echo - 编译后体积: %SIZE_MB% MB
echo.
echo [4/4] 执行瘦身清理(参考 参考项目策略)...
powershell -ExecutionPolicy Bypass -File slim_dist.ps1 -DistPath "dist\%APP_NAME%.dist"
echo.
echo ========================================
echo 编译完成!
echo ========================================
pausebuild_optimized.bat@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
echo ========================================
echo Nuitka 极限优化编译(参考 参考项目)
echo ========================================
REM === 配置区域(请修改为你的实际值) ===
set APP_NAME=你的软件名
set MAIN_FILE=main.py
set ICON_FILE=icon.ico
REM === 自动检测 CPU 核心数 ===
REM 用 Windows 自带环境变量(wmic 在 Win11 22H2+ 已移除,探不到会让 --jobs=0 单线程编译)
set CPU_CORES=%NUMBER_OF_PROCESSORS%
if not defined CPU_CORES set CPU_CORES=4
set /a BUILD_JOBS=%CPU_CORES%
REM === 参考项目的模块排除清单 ===
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%,email.mime,http.server,xmlrpc,pydoc
echo.
echo [1/4] 清理旧编译...
if exist dist rd /s /q dist
if exist build rd /s /q build
echo.
echo [2/4] Nuitka 编译中(应用 参考项目优化策略)...
echo - CPU 核心: %CPU_CORES% (使用 %BUILD_JOBS% 线程)
echo - 模块排除: %EXCLUDE_MODULES%
echo.
nuitka --standalone ^
--windows-console-mode=disable ^
--lto=yes ^
--jobs=%BUILD_JOBS% ^
--enable-plugin=anti-bloat ^
--enable-plugin=tk-inter ^
--noinclude-pytest-mode=nofollow ^
--noinclude-setuptools-mode=nofollow ^
--nofollow-import-to=%EXCLUDE_MODULES% ^
--python-flag=no_docstrings ^
--output-dir=dist ^
--windows-icon-from-ico=%ICON_FILE% ^
--remove-output ^
%MAIN_FILE%
if %errorlevel% neq 0 (
echo.
echo [错误] 编译失败!
pause
exit /b 1
)
echo.
echo [3/4] 统计编译结果...
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 /a SIZE_MB=%TOTAL_SIZE% / 1048576
echo - 编译后体积: %SIZE_MB% MB
echo.
echo [4/4] 执行瘦身清理(参考 参考项目策略)...
powershell -ExecutionPolicy Bypass -File slim_dist.ps1 -DistPath "dist\%APP_NAME%.dist"
echo.
echo ========================================
echo 编译完成!
echo ========================================
pauseslim_dist.ps1param(
[string]$DistPath
)
$ErrorActionPreference = "Continue" # 不静默吞错:删除失败会显示出来,避免假成功
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "dist 瘦身清理(参考 参考项目策略)" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
if (-not (Test-Path $DistPath)) {
Write-Host "[错误] 找不到目录: $DistPath" -ForegroundColor Red
exit 1
}slim_dist.ps1param(
[string]$DistPath
)
$ErrorActionPreference = "Continue" # 不静默吞错:删除失败会显示出来,避免假成功
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "dist 瘦身清理(参考 参考项目策略)" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
if (-not (Test-Path $DistPath)) {
Write-Host "[错误] 找不到目录: $DistPath" -ForegroundColor Red
exit 1
}n========================================" -ForegroundColor Cyan Write-Host "清理完成!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Cyan Write-Host "初始体积: $([math]::Round($InitialSize, 2)) MB" -ForegroundColor Yellow Write-Host "最终体积: $([math]::Round($FinalSize, 2)) MB" -ForegroundColor Green Write-Host "节省空间: $([math]::Round($SavedSize, 2)) MB ($([math]::Round($SavedPercent, 1))%)" -ForegroundColor Cyan Write-Host "========================================n========================================" -ForegroundColor Cyan Write-Host "清理完成!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Cyan Write-Host "初始体积: $([math]::Round($InitialSize, 2)) MB" -ForegroundColor Yellow Write-Host "最终体积: $([math]::Round($FinalSize, 2)) MB" -ForegroundColor Green Write-Host "节省空间: $([math]::Round($SavedSize, 2)) MB ($([math]::Round($SavedPercent, 1))%)" -ForegroundColor Cyan Write-Host "========================================
**预期效果**:节省 **15-30%** 体积
**预期效果**:节省 **15-30%** 体积analyze_dlls.py"""
DLL 依赖分析工具
参考 参考项目的 DLL 管理策略,帮助识别体积大户和优化建议
"""
import sys
from pathlib import Path
def analyze_dlls(dist_path: str):
"""分析 dist 目录中的 DLL 依赖"""
dist_dir = Path(dist_path)
if not dist_dir.exists():
print(f"[错误] 目录不存在: {dist_path}")
return
print("=" * 70)
print("DLL 依赖分析(参考 参考项目策略)")
print("=" * 70)
# 收集所有 DLL
dll_files = list(dist_dir.rglob("*.dll"))
if not dll_files:
print("\n未发现 DLL 文件")
return
# 按大小排序
dll_data = [(dll, dll.stat().st_size) for dll in dll_files]
dll_data.sort(key=lambda x: x[1], reverse=True)
total_size = sum(size for _, size in dll_data)
print(f"\n总 DLL 数量: {len(dll_files)}")
print(f"总 DLL 体积: {total_size / 1024 / 1024:.2f} MB\n")
# 参考项目对比
print("[对比参考] 参考项目的 DLL 情况:")
print(" - 总数量: 71 个")
print(" - 总体积: 93.23 MB")
print(" - 最大的: libopenblas (26.85 MB), opengl32sw (15.25 MB)\n")
# 分析大于 3MB 的 DLL
large_dlls = [(dll, size) for dll, size in dll_data if size > 3 * 1024 * 1024]
if large_dlls:
print("=" * 70)
print("WARNING: 大于 3MB 的 DLL(需重点关注)")
print("=" * 70)
for dll, size in large_dlls:
size_mb = size / 1024 / 1024
relative_path = dll.relative_to(dist_dir)
name_lower = dll.name.lower()
print(f"\n{size_mb:8.2f} MB {dll.name}")
print(f" 位置: {relative_path.parent}")
# 优化建议
suggestions = get_optimization_suggestion(name_lower)
if suggestions:
for suggestion in suggestions:
print(f" {suggestion}")
# 检查冗余 DLL
print("\n" + "=" * 70)
print(" 冗余检查")
print("=" * 70)
# 检查调试版本
debug_dlls = [dll for dll, _ in dll_data if dll.stem.endswith('d')]
if debug_dlls:
print(f"\nWARNING: 发现 {len(debug_dlls)} 个调试版本 DLL(可以删除):")
for dll in debug_dlls:
print(f" - {dll.name}")
else:
print("\nPASS: 未发现调试版本 DLL(已优化)")
# VC++ Runtime
vc_runtimes = [dll for dll, _ in dll_data if 'vcruntime' in dll.name.lower() or 'msvcp' in dll.name.lower()]
if vc_runtimes:
print(f"\n[VC++ Runtime 库] 发现 {len(vc_runtimes)} 个:")
for dll in vc_runtimes:
size_mb = dll.stat().st_size / 1024 / 1024
print(f" - {dll.name} ({size_mb:.2f} MB)")
print(" 这些是必需的,参考项目也包含了这些文件")
# 全部 DLL 列表
print("\n" + "=" * 70)
print(" 完整 DLL 列表(按体积排序,前 20)")
print("=" * 70)
print(f"\n{'体积 (MB)':>10} {'文件名':<30} 位置")
print("-" * 70)
for dll, size in dll_data[:20]:
size_mb = size / 1024 / 1024
relative_path = dll.relative_to(dist_dir)
location = str(relative_path.parent) if relative_path.parent != Path('.') else "根目录"
print(f"{size_mb:10.2f} {dll.name:<30} {location}")
if len(dll_data) > 20:
remaining_size = sum(size for _, size in dll_data[20:]) / 1024 / 1024
print(f"... 还有 {len(dll_data) - 20} 个 DLL,共 {remaining_size:.2f} MB")
def get_optimization_suggestion(dll_name: str) -> list:
"""根据 DLL 名称给出优化建议"""
suggestions = []
if "openblas" in dll_name or "mkl" in dll_name:
suggestions.append("数学运算库,参考项目的 libopenblas 有 26.85 MB")
suggestions.append("如不需要高性能计算可考虑轻量版")
elif "opencv" in dll_name or "ffmpeg" in dll_name:
suggestions.append("OpenCV 相关,参考项目的 opencv_videoio_ffmpeg 有 18.48 MB")
suggestions.append("考虑用 opencv-python-headless")
elif "qt5" in dll_name or "qt6" in dll_name or "pyside" in dll_name:
suggestions.append("Qt 库,参考项目的 Qt5Core 有 5.13 MB")
suggestions.append("可排除不需要的模块(WebEngine, 3D, Charts)")
elif "opengl" in dll_name and "sw" in dll_name:
suggestions.append("OpenGL 软件渲染器,参考项目保留了 15.25 MB")
suggestions.append("通常可以删除(使用硬件渲染)")
elif "d3dcompiler" in dll_name:
suggestions.append("DirectX 编译器,参考项目有 3.53 MB")
elif "mfc140" in dll_name:
suggestions.append("MFC 库,参考项目有 4.89 MB")
return suggestions
if __name__ == "__main__":
if len(sys.argv) < 2:
print("用法: python analyze_dlls.py <dist目录路径>")
print("示例: python analyze_dlls.py dist/main.dist")
sys.exit(1)
analyze_dlls(sys.argv[1])python analyze_dlls.py dist/你的软件名.distanalyze_dlls.py"""
DLL 依赖分析工具
参考 参考项目的 DLL 管理策略,帮助识别体积大户和优化建议
"""
import sys
from pathlib import Path
def analyze_dlls(dist_path: str):
"""分析 dist 目录中的 DLL 依赖"""
dist_dir = Path(dist_path)
if not dist_dir.exists():
print(f"[错误] 目录不存在: {dist_path}")
return
print("=" * 70)
print("DLL 依赖分析(参考 参考项目策略)")
print("=" * 70)
# 收集所有 DLL
dll_files = list(dist_dir.rglob("*.dll"))
if not dll_files:
print("\n未发现 DLL 文件")
return
# 按大小排序
dll_data = [(dll, dll.stat().st_size) for dll in dll_files]
dll_data.sort(key=lambda x: x[1], reverse=True)
total_size = sum(size for _, size in dll_data)
print(f"\n总 DLL 数量: {len(dll_files)}")
print(f"总 DLL 体积: {total_size / 1024 / 1024:.2f} MB\n")
# 参考项目对比
print("[对比参考] 参考项目的 DLL 情况:")
print(" - 总数量: 71 个")
print(" - 总体积: 93.23 MB")
print(" - 最大的: libopenblas (26.85 MB), opengl32sw (15.25 MB)\n")
# 分析大于 3MB 的 DLL
large_dlls = [(dll, size) for dll, size in dll_data if size > 3 * 1024 * 1024]
if large_dlls:
print("=" * 70)
print("WARNING: 大于 3MB 的 DLL(需重点关注)")
print("=" * 70)
for dll, size in large_dlls:
size_mb = size / 1024 / 1024
relative_path = dll.relative_to(dist_dir)
name_lower = dll.name.lower()
print(f"\n{size_mb:8.2f} MB {dll.name}")
print(f" 位置: {relative_path.parent}")
# 优化建议
suggestions = get_optimization_suggestion(name_lower)
if suggestions:
for suggestion in suggestions:
print(f" {suggestion}")
# 检查冗余 DLL
print("\n" + "=" * 70)
print(" 冗余检查")
print("=" * 70)
# 检查调试版本
debug_dlls = [dll for dll, _ in dll_data if dll.stem.endswith('d')]
if debug_dlls:
print(f"\nWARNING: 发现 {len(debug_dlls)} 个调试版本 DLL(可以删除):")
for dll in debug_dlls:
print(f" - {dll.name}")
else:
print("\nPASS: 未发现调试版本 DLL(已优化)")
# VC++ Runtime
vc_runtimes = [dll for dll, _ in dll_data if 'vcruntime' in dll.name.lower() or 'msvcp' in dll.name.lower()]
if vc_runtimes:
print(f"\n[VC++ Runtime 库] 发现 {len(vc_runtimes)} 个:")
for dll in vc_runtimes:
size_mb = dll.stat().st_size / 1024 / 1024
print(f" - {dll.name} ({size_mb:.2f} MB)")
print(" 这些是必需的,参考项目也包含了这些文件")
# 全部 DLL 列表
print("\n" + "=" * 70)
print(" 完整 DLL 列表(按体积排序,前 20)")
print("=" * 70)
print(f"\n{'体积 (MB)':>10} {'文件名':<30} 位置")
print("-" * 70)
for dll, size in dll_data[:20]:
size_mb = size / 1024 / 1024
relative_path = dll.relative_to(dist_dir)
location = str(relative_path.parent) if relative_path.parent != Path('.') else "根目录"
print(f"{size_mb:10.2f} {dll.name:<30} {location}")
if len(dll_data) > 20:
remaining_size = sum(size for _, size in dll_data[20:]) / 1024 / 1024
print(f"... 还有 {len(dll_data) - 20} 个 DLL,共 {remaining_size:.2f} MB")
def get_optimization_suggestion(dll_name: str) -> list:
"""根据 DLL 名称给出优化建议"""
suggestions = []
if "openblas" in dll_name or "mkl" in dll_name:
suggestions.append("数学运算库,参考项目的 libopenblas 有 26.85 MB")
suggestions.append("如不需要高性能计算可考虑轻量版")
elif "opencv" in dll_name or "ffmpeg" in dll_name:
suggestions.append("OpenCV 相关,参考项目的 opencv_videoio_ffmpeg 有 18.48 MB")
suggestions.append("考虑用 opencv-python-headless")
elif "qt5" in dll_name or "qt6" in dll_name or "pyside" in dll_name:
suggestions.append("Qt 库,参考项目的 Qt5Core 有 5.13 MB")
suggestions.append("可排除不需要的模块(WebEngine, 3D, Charts)")
elif "opengl" in dll_name and "sw" in dll_name:
suggestions.append("OpenGL 软件渲染器,参考项目保留了 15.25 MB")
suggestions.append("通常可以删除(使用硬件渲染)")
elif "d3dcompiler" in dll_name:
suggestions.append("DirectX 编译器,参考项目有 3.53 MB")
elif "mfc140" in dll_name:
suggestions.append("MFC 库,参考项目有 4.89 MB")
return suggestions
if __name__ == "__main__":
if len(sys.argv) < 2:
print("用法: python analyze_dlls.py <dist目录路径>")
print("示例: python analyze_dlls.py dist/main.dist")
sys.exit(1)
analyze_dlls(sys.argv[1])python analyze_dlls.py dist/你的软件名.distbuild_optimized.batset APP_NAME=你的软件名 REM 改成实际名称
set MAIN_FILE=main.py REM 你的主程序文件
set ICON_FILE=icon.ico REM 你的图标文件build_optimized.batset APP_NAME=你的软件名 REM 改成实际名称
set MAIN_FILE=main.py REM 你的主程序文件
set ICON_FILE=icon.ico REM 你的图标文件undefinedundefinedundefinedundefinedpython analyze_dlls.py dist/你的软件名.distpython analyze_dlls.py dist/你的软件名.distpip uninstall opencv-python
pip install opencv-python-headlessundefinedpip uninstall opencv-python
pip install opencv-python-headlessundefined
**删除软件渲染器**(如果不需要)
```powershell
**删除软件渲染器**(如果不需要)
```powershell
---
---nuitka --static-libpython=yes ...nuitka --static-libpython=yes ...; WARNING: VC++ 运行库架构必须与 Python/Nuitka 构建架构一致。
; 本 skill 推荐 32 位 Python,故默认捆绑 vc_redist.x86.exe;
; 若用 64 位 Python 编译,请把下面两处改为 vc_redist.x64.exe。
[Files]
Source: "{#MySourceDir}\..\vc_redist.x86.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
[Run]
Filename: "{tmp}\vc_redist.x86.exe"; Parameters: "/quiet /norestart"; StatusMsg: "正在安装运行库..."; Flags: waituntilterminated; WARNING: VC++ 运行库架构必须与 Python/Nuitka 构建架构一致。
; 本 skill 推荐 32 位 Python,故默认捆绑 vc_redist.x86.exe;
; 若用 64 位 Python 编译,请把下面两处改为 vc_redist.x64.exe。
[Files]
Source: "{#MySourceDir}\..\vc_redist.x86.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
[Run]
Filename: "{tmp}\vc_redist.x86.exe"; Parameters: "/quiet /norestart"; StatusMsg: "正在安装运行库..."; Flags: waituntilterminated; =====================================================================
; WARNING: 商业级 Python 安装脚本 (Inno Setup 6.x)
; 特性:LZMA2 极限压缩 | 全中文 | 完整元数据 | 无残留卸载
; 参考:参考项目(323 MB, LZMA2 压缩)
; =====================================================================
; --- 1. 参数定义 ---
#define MyAppName "{{APP_NAME}}"
#define MyAppVersion "{{APP_VERSION}}"
#define MyAppPublisher "{{PUBLISHER}}"
#define MyAppURL "{{APP_URL}}"
#define MyAppExeName "{{EXE_NAME}}"
#define MySourceDir "{{SOURCE_DIR}}"
#define MyOutputDir "{{OUTPUT_DIR}}"
;#define MyIconPath "{{ICON_PATH}}"
[Setup]
; --- 身份识别 ---
AppId={{GENERATE_RANDOM_GUID}}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
; --- 安装路径与权限 ---
DefaultDirName={autopf}\{#MyAppName}
DefaultGroupName={#MyAppName}
DisableDirPage=no
DisableProgramGroupPage=no
PrivilegesRequired=admin
; --- 输出设置 ---
OutputDir={#MyOutputDir}
OutputBaseFilename=Setup_{#MyAppName}_v{#MyAppVersion}
; --- 视觉体验 ---
WizardStyle=modern
#ifdef MyIconPath
SetupIconFile={#MyIconPath}
UninstallDisplayIcon={app}\{#MyAppExeName}
#endif
; --- 核心压缩 (参考 参考项目) ---
Compression=lzma2/ultra64
SolidCompression=yes
LZMAUseSeparateProcess=yes
; --- 架构 ---
; 注意:仅 64 位 Python 构建才设此项。本 skill 推荐 32 位 Python——
; 32 位构建请保持注释,使应用按 32 位安装并与上面捆绑的 vc_redist.x86.exe 匹配。
; 仅当用 64 位 Python 编译时才取消注释。
;ArchitecturesInstallIn64BitMode=x64compatible
[Languages]
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
[Files]
Source: "{#MySourceDir}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
[UninstallDelete]
Type: filesandordirs; Name: "{app}\*"
[Icons]
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\卸载 {#MyAppName}"; Filename: "{uninstallexe}"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppName}}"; Flags: nowait postinstall skipifsilent; =====================================================================
; WARNING: 商业级 Python 安装脚本 (Inno Setup 6.x)
; 特性:LZMA2 极限压缩 | 全中文 | 完整元数据 | 无残留卸载
; 参考:参考项目(323 MB, LZMA2 压缩)
; =====================================================================
; --- 1. 参数定义 ---
#define MyAppName "{{APP_NAME}}"
#define MyAppVersion "{{APP_VERSION}}"
#define MyAppPublisher "{{PUBLISHER}}"
#define MyAppURL "{{APP_URL}}"
#define MyAppExeName "{{EXE_NAME}}"
#define MySourceDir "{{SOURCE_DIR}}"
#define MyOutputDir "{{OUTPUT_DIR}}"
;#define MyIconPath "{{ICON_PATH}}"
[Setup]
; --- 身份识别 ---
AppId={{GENERATE_RANDOM_GUID}}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
; --- 安装路径与权限 ---
DefaultDirName={autopf}\{#MyAppName}
DefaultGroupName={#MyAppName}
DisableDirPage=no
DisableProgramGroupPage=no
PrivilegesRequired=admin
; --- 输出设置 ---
OutputDir={#MyOutputDir}
OutputBaseFilename=Setup_{#MyAppName}_v{#MyAppVersion}
; --- 视觉体验 ---
WizardStyle=modern
#ifdef MyIconPath
SetupIconFile={#MyIconPath}
UninstallDisplayIcon={app}\{#MyAppExeName}
#endif
; --- 核心压缩 (参考 参考项目) ---
Compression=lzma2/ultra64
SolidCompression=yes
LZMAUseSeparateProcess=yes
; --- 架构 ---
; 注意:仅 64 位 Python 构建才设此项。本 skill 推荐 32 位 Python——
; 32 位构建请保持注释,使应用按 32 位安装并与上面捆绑的 vc_redist.x86.exe 匹配。
; 仅当用 64 位 Python 编译时才取消注释。
;ArchitecturesInstallIn64BitMode=x64compatible
[Languages]
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
[Files]
Source: "{#MySourceDir}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
[UninstallDelete]
Type: filesandordirs; Name: "{app}\*"
[Icons]
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\卸载 {#MyAppName}"; Filename: "{uninstallexe}"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppName}}"; Flags: nowait postinstall skipifsilent| 占位符 | 说明 | 示例值 |
|---|---|---|
| 软件显示名称 | |
| 版本号 | |
| 发布者/公司名 | |
| 官网地址 | |
| 主程序文件名 | |
| Nuitka dist 文件夹路径 | |
| 安装包输出路径 | |
| 图标文件路径 | |
| 需生成唯一GUID | 使用 Inno Setup "Tools > Generate GUID" |
| 占位符 | 说明 | 示例值 |
|---|---|---|
| 软件显示名称 | |
| 版本号 | |
| 发布者/公司名 | |
| 官网地址 | |
| 主程序文件名 | |
| Nuitka dist 文件夹路径 | |
| 安装包输出路径 | |
| 图标文件路径 | |
| 需生成唯一GUID | 使用 Inno Setup "Tools > Generate GUID" |
--standalonePYTHONIOENCODING=utf-8x64ArchitecturesInstallIn64BitMode=x64compatible--disable-console--windows-console-mode=disable_nuitka_temp.exe--standalonePYTHONIOENCODING=utf-8x64ArchitecturesInstallIn64BitMode=x64compatible--disable-console--windows-console-mode=disable_nuitka_temp.exe| 优化组合 | 体积减少 | 启动提升 | 风险等级 |
|---|---|---|---|
| 基础编译 | 基准 | 基准 | 无 |
+ | 5-10% | 10-20% | PASS: 无 |
| + anti-bloat | 15-25% | - | PASS: 无 |
| + 模块排除 | 20-35% | 5% | PASS: 无 |
| + dist 瘦身 | 25-40% | - | PASS: 无 |
| + 32 位编译 | 40-60% | - | PASS: 无 |
| 全部组合 | 45-65% | 15-25% | PASS: 无风险 |
WARNING: 不建议使用 UPX 压缩,虽然能进一步减小体积,但极易触发杀毒软件误报。
| 优化组合 | 体积减少 | 启动提升 | 风险等级 |
|---|---|---|---|
| 基础编译 | 基准 | 基准 | 无 |
+ | 5-10% | 10-20% | PASS: 无 |
| + anti-bloat | 15-25% | - | PASS: 无 |
| + 模块排除 | 20-35% | 5% | PASS: 无 |
| + dist 瘦身 | 25-40% | - | PASS: 无 |
| + 32 位编译 | 40-60% | - | PASS: 无 |
| 全部组合 | 45-65% | 15-25% | PASS: 无风险 |
WARNING: 不建议使用 UPX 压缩,虽然能进一步减小体积,但极易触发杀毒软件误报。