I wrote a GUI application in Python 3 using Kivy that needs to be distributed to non tech savy people that need an executable.

The first time I tried to build an .exe I got a 800MB dist folder due to Numpy being the mkl version and not the OpenBLAS one. I fixed that by using a dedicated environment for my application (from this question), now I'm down to 170 MB which is still large even when zipped. I hoped I could reach 50MB or even lower but I cannot understand what the documentation is suggesting to do... I'm sure there are a lot of kivy dependencies which are inserted in the .exe dist but not used.

Right now I'm using a standard .spec file as suggested in the documentation:

from kivy.deps import sdl2, glew
block_cipher = None


a = Analysis(['UploadTimeProgramGUI.py'],
         pathex=['C:\\Users\\M\\Desktop\\kivyapp\\test'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='test',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )

coll = COLLECT(exe, Tree('C:\\Users\\M\\Desktop\\kivyapp\\test'),
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=True,
               name='test')

How can I reduce the size of the executable (dist folder that will be indeed distributed) further by excluding unused kivy dependencies?

Userful information:

  • Application written in: Python 3.7 Anaconda distribution
  • Imports: kivy, pandas, re (standard lib), os (standard lib)
  • Development and target OS: Windows 10
  • Other notes: App is using no videos nor sounds, its a simple gui with some buttons, labels, listview and listadapter and a few popups.

0 Answers