Search code examples
pythonpython-3.xpyqt5exepyinstaller

Large file size after building pyqt to exe with pyinstaller


The following code is the module I used in my pyqt widget, but after I use pyinstaller to build exe file, the file size is 233MB large.

How can I reduce the file size?

I tried to create a new virtual environment, but there is no improvement, and I also tried to add excludes=['mkl','whl'] in my pyinstaller spec file, but no improve as well.

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 is the UI code I build with qtdesigner, the module it use is :

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

Solution

  • Finally I reduce my exe file size from 233MB to 64MB by solution provided here :

    1. Create a new conda environment pyinstaller-env
    2. install numpy with conda install conda-forge::numpy "blas=*=openblas"
    3. Switch environment to pyinstaller-env and package my QT application.