Python 使用pyinstaller将pyqt构建为exe后的大文件大小

Python 使用pyinstaller将pyqt构建为exe后的大文件大小,python,python-3.x,pyqt5,exe,pyinstaller,Python,Python 3.x,Pyqt5,Exe,Pyinstaller,下面的代码是我在pyqt小部件中使用的模块,但是在我使用pyinstaller构建exe文件之后,文件大小是233MB 如何减小文件大小 我尝试创建一个新的虚拟环境,但没有改进,我还尝试在我的pyinstallerspec文件中添加excludes=['mkl','whl'],但也没有改进 from PyQt5.QtWidgets import QMainWindow, QMessageBox, QApplication, QFileDialog from PyQt5.QtGui import

下面的代码是我在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
main窗口
是我使用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

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

  • 创建新的conda环境
    pyinstaller env
  • 使用
    conda安装conda forge::numpy“blas=*=openblas”
  • 将环境切换到
    pyinstaller env
    并打包我的QT应用程序

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

    以下是我所做的:-

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

    创建的文件夹有很多垃圾和不需要的东西,所以首先删除应用程序中未使用的DLL文件

    然后,对于其余的文件,使用点击并试用的方法,删除一个文件,看看应用程序是否仍能正常工作,如果不能,则恢复该文件并尝试使用其他文件

    完成后,在所有
    .pyd
    文件上使用UPX(lzma模式)。 除了一些dll(如VCRUNTIME.dll),大多数dll都可以用UPX压缩,因此您也必须对dll文件执行点击跟踪

    最后,您可以压缩应用程序上的任何图像(如果有)

    完成(◠‿◕)