【问题标题】:Large file size after building pyqt to exe with pyinstaller使用 pyinstaller 将 pyqt 构建为 exe 后文件很大
【发布时间】:2019-10-22 03:27:54
【问题描述】:

以下代码是我在pyqt小部件中使用的模块,但是我使用pyinstaller构建exe文件后,文件大小为233MB。

如何减小文件大小?

我尝试创建一个新的虚拟环境,但没有任何改善,我也尝试在我的 pyinstaller spec 文件中添加excludes=['mkl','whl'],但也没有改善。

from PyQt5.QtWidgets import QMainWindow, QMessageBox, QApplication, QFileDialog
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import Qt, pyqtSignal, QEvent
import sys
from glob import glob
from numpy import array as nparray
from PIL.Image import open as imopen
from win32gui import GetWindowText, GetForegroundWindow
from MainWindow import Ui_MainWindow, resource_path
from qimage2ndarray import array2qimage
from shutil import move
from os import makedirs, chdir, getcwd
from os import path as ospath

MainWindow是我用qtdesigner构建的UI代码,它使用的模块是:

from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QStatusBar
from PyQt5.QtCore import QRect, Qt, QSize, QMetaObject, QCoreApplication
from PyQt5.QtGui import QFont, QIcon, QPixmap
import sys
from os.path import join, abspath

【问题讨论】:

    标签: python python-3.x pyqt5 exe pyinstaller


    【解决方案1】:

    最后我通过here 提供的解决方案将我的 exe 文件大小从 233MB 减少到 64MB:

    1. 新建conda环境pyinstaller-env
    2. 安装numpyconda install conda-forge::numpy "blas=*=openblas"
    3. 将环境切换到pyinstaller-env 并打包我的QT 应用程序。

    【讨论】:

      【解决方案2】:

      对于我的应用,我能够将大小从 80mb 减小到 15mb

      这是我所做的:-

      首先在一个目录模式下使用pyinstaller

      创建的文件夹有很多垃圾和不需要的东西所以首先删除你知道你没有在应用程序中使用的DLL文件。

      然后对于其余文件使用 hit-and-trial 方法,删除一个文件并查看应用程序是否仍然正常工作,如果没有,则恢复该文件并尝试使用其他文件。

      完成后,对所有 .pyd 文件使用 UPX(在 lzma 模式下)。 除了一些(如 VCRUNTIME.dll)外,大多数 DLL 也可以使用 UPX 压缩,因此您也必须对 DLL 文件进行命中和跟踪。

      最后你可以在你的应用中压缩任何图片(如果有的话)。

      完成(◠‿◕)

      【讨论】:

        猜你喜欢
        • 2014-01-19
        • 1970-01-01
        • 2019-03-20
        • 2017-10-17
        • 1970-01-01
        • 2013-10-15
        • 2018-09-20
        • 2013-11-08
        • 2016-02-12
        相关资源
        最近更新 更多