Reputation: 137
I have a script that I want to compile into an executable. I'm using Pyinstaller for this task and the exe file generated is too large.
There are several imports, one of them is pywinauto. If I comment pywinauto imports I get an executable with 20mb. With pywinauto I get an executable with 232mb!
Note: I'm running pyinstaller from a virtual environment in which I have just installed the necessary python dependencies that I'm using in the script.
Here is a list of the imports I'm using:
import os,subprocess,datetime, argparse, math, win32con
import boto3
from botocore.exceptions import NoCredentialsError
from botocore.client import Config
import wx,wx.adv
from pubsub import pub
from win32api import GetSystemMetrics
from pywinauto.application import Application
from pywinauto.keyboard import SendKeys
from pywinauto.findwindows import find_window
from base64 import b64decode
from zlib import decompress
from io import BytesIO
Pyinstaller command that I'm running:
pyinstaller --noconsole --onefile --i=rec.ico --clean script.py
pip list
in my virtal environment:
Package Version
--------------- --------
boto3 1.9.246
botocore 1.12.246
comtypes 1.1.7
docutils 0.15.2
jmespath 0.9.4
Pillow 6.2.0
pip 19.2.3
pubsub 0.1.2
pypiwin32 223
python-dateutil 2.8.0
pywin32 225
pywinauto 0.6.7
s3transfer 0.2.1
setuptools 40.8.0
six 1.12.0
urllib3 1.25.6
wheel 0.33.6
wxPython 4.0.6
Is there any way to reduce the executable size?
I'm using pywinauto basically to send a keyboard shortcut command to another application from my script. If there's an alternative library to do this that would make my executable smaller I would certainly try it.
Thanks!
====================
EDIT:
I tried to compile with:
pyinstaller --noconsole --onedir --i=rec.ico --clean script.py
Now I get a folder with 660mb!!! And the application loads WAY faster (it was taking about 15s to load before, now it's almost instantly).
The folder of the application has a LOT of dll files, the 19 largest of them summing up to 537 Mb.
Any suggestions on how to trim that?
Upvotes: 1
Views: 935
Reputation: 137
I did a fresh install of python 3.7, since I was using Anaconda's Python distribution before, installed just the packages I needed and compiled it with pyinstaller again. Now I have a 35Mb file with --onefile
or a 120Mb folder with --onedir
. I'll probably be using onedir because the application loads faster that way. I don't think it's the ideal file size but it's certaily way better than before (open to suggestions in case anyone has an idea on how to further reduce the size of the application). Thanks Vasily for the help!
Upvotes: 1