7

I've made simple code editor using wxPython. File size (python files) is 1.3 KB. But when I create executable using PyInstaller, I get 30 MB file! Is there a way to decrease file size? Btw, I am not importing whole wx library, only components I need (ex from wx import Frame).

Using Linux, Fedora 18 64bit.

JadedTuna
  • 1,783
  • 2
  • 18
  • 32

2 Answers2

6

wxPython is a big library so when you create an executable, they tend to end up being between 20 and 30 MB. Also note that Python itself is kind of bulky because Python is an interpreted language. So you are also including the Python interpreter when you create the exe.

With py2exe, I have gotten the executable below 10 MB, but it's a pain and doesn't work for all projects. It really depends on what else you are using. You can read about my adventures with py2exe here.

The other way to get it smaller is to use a compression program. That sometimes works and sometimes doesn't.

You can also tell most of these binary creation tools to exclude items. You can try that too.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
3

I shipped a fairly simple wxPython app and it ended up being ~9.8MB.

If you utilize the ArchiveViewer.py script that's part of PyInstaller you can determine what's taking up so much space.

This was with python 2.7.5, without UPX, and excluding these modules:

excludesPassedToAnalysis = ['ssl',
 '_ssl',
 # coverage uses _socket. :(
 #'_socket',
 'select',
 'pywin',
 'unittest',
 'win32ui',
 'bz2',
 'doctest',
 'os2emxpath',
 'servicemanager',
 'xml.parsers.expat',
 'sitecustomize',
 'tarflie',
 'email',
 'urllib',
 'urllib2',
 # This exclude isn't optional in order to get pubsub working
 # correctly in wxPython 2.9.3 or later.
 'wx.lib.pubsub.autosetuppubsubv1']

# These are removed from a.pure after the Analysis object is created.
excludeEncodings = \
['encodings.base_64_codec',
 'encodings.big5',
 'encodings.big5hkscs',
 'encodings.bz2_codec',
 'encodings.cp037',
 'encodings.cp1006',
 'encodings.cp1026',
 'encodings.cp1140',
 'encodings.cp1258',
 'encodings.cp424',
 'encodings.cp437',
 'encodings.cp500',
 'encodings.cp720',
 'encodings.cp737',
 'encodings.cp775',
 'encodings.cp850',
 'encodings.cp852',
 'encodings.cp855',
 'encodings.cp856',
 'encodings.cp857',
 'encodings.cp858',
 'encodings.cp860',
 'encodings.cp861',
 'encodings.cp862',
 'encodings.cp863',
 'encodings.cp864',
 'encodings.cp865',
 'encodings.cp866',
 'encodings.cp869',
 'encodings.cp874',
 'encodings.cp875',
 'encodings.cp932',
 'encodings.cp949',
 'encodings.cp950',
 'encodings.euc_jis_2004',
 'encodings.euc_jisx0213',
 'encodings.euc_jp',
 'encodings.euc_kr',
 'encodings.gb18030',
 'encodings.gb2312',
 'encodings.gbk',
 'encodings.hex_codec',
 'encodings.hp_roman8',
 'encodings.hz',
 'encodings.iso2022_jp',
 'encodings.iso2022_jp_1',
 'encodings.iso2022_jp_2',
 'encodings.iso2022_jp_2004',
 'encodings.iso2022_jp_3',
 'encodings.iso2022_jp_ext',
 'encodings.iso2022_kr',
 'encodings.iso8859_10',
 'encodings.iso8859_11',
 'encodings.iso8859_13',
 'encodings.iso8859_14',
 'encodings.iso8859_15',
 'encodings.iso8859_16',
 'encodings.iso8859_2',
 'encodings.iso8859_3',
 'encodings.iso8859_4',
 'encodings.iso8859_5',
 'encodings.iso8859_6',
 'encodings.iso8859_7',
 'encodings.iso8859_8',
 'encodings.iso8859_9',
 'encodings.johab',
 'encodings.koi8_r',
 'encodings.koi8_u',
 'encodings.mac_arabic',
 'encodings.mac_centeuro',
 'encodings.mac_croatian',
 'encodings.mac_cyrillic',
 'encodings.mac_farsi',
 'encodings.mac_greek',
 'encodings.mac_iceland',
 'encodings.mac_latin2',
 'encodings.mac_roman',
 'encodings.mac_romanian',
 'encodings.mac_turkish',
 'encodings.mbcs',
 'encodings.palmos',
 'encodings.ptcp154',
 'encodings.quopri_codec',
 'encodings.raw_unicode_escape',
 'encodings.rot_13',
 'encodings.shift_jis',
 'encodings.shift_jis_2004',
 'encodings.shift_jisx0213',
 'encodings.string_escape',
 'encodings.tis_620',
 'encodings.undefined',
 'encodings.utf_32',
 'encodings.utf_32_be',
 'encodings.utf_32_le',
 'encodings.utf_7',
 'encodings.uu_codec',
 'encodings.zlib_codec',]
Bill Tutt
  • 414
  • 4
  • 6
  • Could you explain how to use pyi-archive_viewer to find the biggest dependencies in size? Because all I get is a list of names :-/ Also, where do you put the two exclusion lists? In spec's excludes field? You concatenate both beforehand? – gaborous Aug 06 '17 at 22:39
  • The spec file isn't easy to get access to at the moment, but if I recall correctly you use the O command for pyi-archive-viewer that will then dump out the data you see in the show method at: https://github.com/pyinstaller/pyinstaller/blob/develop/PyInstaller/utils/cliutils/archive_viewer.py. – Bill Tutt Aug 10 '17 at 12:49
  • The first exclude above gets passed into the Analysis call. The second exclude list as mentioned in the comment is are the module names that get removed from the pure property of the result of the Analysis call. – Bill Tutt Aug 10 '17 at 12:51