Reputation: 3729
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
Upvotes: 0
Views: 5112
Reputation: 3729
Finally I reduce my exe file size from 233MB to 64MB by solution provided here :
pyinstaller-env
numpy
with conda install conda-forge::numpy "blas=*=openblas"
pyinstaller-env
and package my QT application.Upvotes: 2
Reputation: 1871
For my app I was able to reduce size from 80mb to 15mb
Here is what I did :-
First Use pyinstaller in one directory mode
The created folder has a lot of garbage and unrequired stuff so first delete the DLL files which you know you have not used in application.
Then for rest of files use hit-and-trial method, delete one file and see if app is still working properly, if not then restore that file and try with some other file.
After you are done, use UPX (in lzma mode) on all .pyd
files.
Most of DLLs can also be compressed with UPX except some (like VCRUNTIME.dll), so you will have to do hit and trail for DLL files too.
Finally you can compress any images (if any) on your app.
Done (◠‿◕)
Upvotes: 3