Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to reduce size of exe using py2exe

I developed a small program using python and wxwidgets. It is a very simple program that uses only a mini frame to display some information when needed, and the rest of the time it shows nothing, only an icon in the taskbar.

When I build the exe using py2exe (single file exe mode, optimized), I get a 6MB size file!

I tried not including some libraries or dll that were not needed but still, I can't see why I get such a big file for just a mini frame and an icon in the taskbar.

Is there any way to reduce the size of the exe generated with py2exe?

here is what I did to reduce a bit myself:

options = {"py2exe":{"excludes" : ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
                                'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
                                'Tkconstants', 'Tkinter'],
                    "dll_excludes": ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
                                'tk84.dll'],

Thanks.

like image 744
attwad Avatar asked Oct 24 '09 12:10

attwad


1 Answers

The fact that your program is simple does not mean that it's small. Your program has many dependency through the wxWidget stack and 6 Mb does not look that big with all this in mind.

But, back to the question. To shrink a py2exe generated program, you can do a few obvious things:

  1. Distribute less stuff: it seems you already started this road. Look at everything that is distributed along with your program and eliminate it if it's not needed. DllDepend can tell you why a DLL is distributed with your program (probably because a pyd needs it). For other modules, remove them and try if it still works...

  2. Compress it better: run upx on each of your dll. Compress your final program/archive with 7zip maximum compression level.

like image 101
Philippe F Avatar answered Oct 04 '22 15:10

Philippe F