Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyInstaller very big file size

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.

like image 915
JadedTuna Avatar asked Oct 08 '13 13:10

JadedTuna


People also ask

Which is better py2exe or PyInstaller?

In PyInstaller it is easy to create one exe, By default both create a bunch of exes & dlls. In py2exe its easier to embed manifest file in exe, useful for run as administrator mode in windows vista and beyond. Pyinstaller is modular and has a feature of hooks to include files in the build that you like.

Why is PyInstaller slow?

PyInstaller's bootloader is usually quite fast in one-dir mode, but it can be much slower in one-file mode, because it depacks everything into a temporary directory. On Windows, I/O is very slow, and then you have antiviruses that will want to double check all those DLL files. PyQt itself is a non-issue.

Does PyInstaller EXE need Python?

They do not need to have Python installed at all. The output of PyInstaller is specific to the active operating system and the active version of Python. This means that to prepare a distribution for: a different OS.


2 Answers

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.

like image 162
Mike Driscoll Avatar answered Oct 20 '22 17:10

Mike Driscoll


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',]
like image 23
Bill Tutt Avatar answered Oct 20 '22 19:10

Bill Tutt