zhu333.com
分享优秀实用的工具

PyInstaller/Nuitka打包Python3.11+PyQt6的文件大概体积是多大?

实测环境:Windows 10 x64 + Python 3.11.8 + PyQt6 6.4.2(仅核心模块:QtWidgets/QtCore/QtGui),最简界面(主窗口+按钮)。

核心体积对比

打包工具 打包模式 原始体积 UPX极致压缩后体积 启动时间(Windows 10)
PyInstaller 单文件(-F) ~32MB ~20MB ~1.2秒
PyInstaller 文件夹(-D) ~85MB ~0.5秒
Nuitka 单文件(–onefile) ~18MB ~11MB ~0.4秒
Nuitka 文件夹(–standalone) ~40MB ~0.2秒

关键变量影响

  • PyQt6精简与否:未精简全模块体积比精简后大40%(PyInstaller 55MB→32MB,Nuitka 30MB→18MB);
  • 原生依赖增量:几乎无影响(Nuitka+0.5~1MB,PyInstaller无增量);
  • Nuitka编译工具:MinGW64比MSVC体积小10%(18MB vs 20MB);
  • 复杂PyQt6组件:含QtCharts/QtSvg时,Nuitka+3~5MB,PyInstaller+5~8MB。

最简测试代码

import sys
import os
import json
import threading
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Test")
        self.setGeometry(100, 100, 300, 200)
        btn = QPushButton("Click", self)
        btn.clicked.connect(self.on_click)

    def on_click(self):
        print(os.getcwd())
        print(json.dumps({"test": 123}))
        threading.Thread(target=lambda: print("Thread run")).start()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())
注意:软件中的广告/弹窗/各种联系方式,等信息切勿相信,注意鉴别,以免上当受骗!
声明:本站部分资源来源于网络,仅供个人学习和研究,不允许用于商业/非法用途,否则法律问题自行承担。