3

I'm using Pyinstaller to generate an executable of a Python3 application that includes a UI made with PySide2.

Using using the --onefile flag the resulting .exe is huge,140 MB.

I tried generating without --onefile flag and take a look what was included in the dist folder: to my surprise everything from PySide2 was included, hence the size.

Keeping in mind that I imported only a few thing from PySide2 (namely: QDialog, QLabel, QPushButton, QApplication, QVBoxLayout) I proceded to manually delete clearly unnecessary files (i.e. QtBluetooth, QtCharts...) and the main executable still works perfectly.

Is there a way to either:

a. proceed to generate the single file executable after the manual removal of unneccessary files

or

b. specify exactly what from PySide should be packed? The import in the Python script looks like from PySide2.QtWidgets import QDialog, QLabel, QPushButton, QApplication, QVBoxLayout but everything is being packed instead.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 1
    This doesn't answer either of your questions, so I'm leaving it as a comment. A few weeks ago I got my app down from 100+ MiB to 35 MiB by creating a `venv`. `pip install` only the packages you need (in my case openpyxl PyPDF2 reportlab PyQt5 winshell pywin32, in addition to pyinstaller). Don't forget to use UPX, by using the `--upx-dir` switch, followed by your UPX directory. – GordonAitchJay Aug 30 '21 at 11:28

1 Answers1

0

Ah, You are not creating the build in a separate virtual environment.

Create a virtual environment just for build purpose and install the packages you need in this environment.

in your cmd execute these to create a virtual enviornment

python -m venv build_env

cd build_env

C:\build_env\Scripts\Activate

you will see this >>(build_env) C:\build_env

Install all the packages you need for your script, start with pyinstaller

pip install pyinstaller

Once you are all installed, build the exe as before. The exe built using the virtual environment should be smaller in size!!