0

I created a PyQT application that depends on a huge amount of packages and want to deploy it now. The exe file is generated with the use of PyInstaller and onedir mode. When I start the main.exe inside a command prompt no errors are displayed and the applications starts as wanted. The problem is that the startup process takes about 20min what is really annoying. The distribution folder has a size of 1.3 GB. Are there any ways to speed up the startup process or do I have to use an alternative to PyInstaller? My .spec files looks like this:

# -*- mode: python -*-

import glob
import rasterio
import pkgutil
from PyInstaller.utils.hooks import collect_data_files 


block_cipher = None

bins = glob.glob(rasterio.__path__[0] + '\\*pyd')
binaries = [(bin,'rasterio') for bin in bins]

additional_packages = list()
for package in pkgutil.iter_modules(rasterio.__path__, prefix="rasterio."):
    additional_packages.append(package.name)

datas = collect_data_files('geopandas',subdir = 'datasets')
datas.append(('C:\\User\\FalterR\\Desktop\\AutoSeg 945\\tool_autoseg\\classifier\\runtime_regression.joblib','clf'))
datas.append(('C:\\User\\FalterR\\Desktop\\AutoSeg 945\\tool_autoseg\\data\\runtime_logfile.csv','csv'))
datas.append(('C:\\User\\FalterR\\Desktop\\AutoSeg 945\\tool_autoseg\\view\\logo_rc.py','.'))

a = Analysis(['main.py'],
             pathex=['C:\\User\\FalterR\\Desktop\\AutoSeg 945'],
             binaries=binaries,
             datas=collect_data_files('geopandas',subdir='datasets'),
             hiddenimports=additional_packages,
             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='main',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='main')
  • I already changed all imports inside my code, so only the neccessary functions are used. e.g import pandas as pd --> from pandas import DataFrame
  • I tried to setup a new conda environment without any uneccessary packages
  • Anti virus protection can not be turned off due to company regulations as suggested in different posts
Robin
  • 41
  • 4
  • 1.3gb?!? What's in that folder? – musicamante Apr 12 '22 at 12:23
  • Try pypy or cython? – user662650 Apr 12 '22 at 21:02
  • Most of it are dll files – Robin Apr 13 '22 at 06:50
  • @Robin dll files of what? Besides, in the code above there's no reference to the modules you're using. – musicamante Apr 13 '22 at 07:56
  • Most of the files were mkl files from the Intel Math Kernel Library that is used by numpy, pandas, scipy etc. I followed the suggestions from this post (https://stackoverflow.com/questions/43886822/pyinstaller-with-pandas-creates-over-500-mb-exe/48846546#48846546) and installed the mentioned libraries without mkl files. It decreased the size of the dist folder from 1.3GB to 500MB but did not reduce the startup time. – Robin Apr 13 '22 at 08:49
  • @Robin if you're using the `--onefile` mode, that's expected: pyinstaller need to decompress the whole package before being able to use it. Disable that and it should work fine. If your issue is about distribution, then consider actual installers, like InnoSetup. – musicamante Apr 13 '22 at 09:15
  • I did use the --onedir mode so far. – Robin Apr 13 '22 at 10:51
  • I solved the problem by creating a new conda environment, install all dependencies with pip and not with conda and add the path to the upx packager. – Robin Apr 13 '22 at 13:56
  • Steps: 1. Setup new conda env and install all dependencies with pip (very important to avoid the installation of numpy with mkl packages) 2. Download upx packager (I used upx-3.96-win64.zip) from: https://github.com/upx/upx 3. Run pyinstaller --upx-dir ./path/to/upx-folder --noconfirm main.spec – Robin Apr 13 '22 at 14:00

0 Answers0