views:

44

answers:

2

I have just made a small little app of a Python wxPython script with py2app. Everything worked as advertised, but the app is pretty big in size. Is there any way to optimize py2app to make the app smaller in size?

A: 

py2app or any other such packager mostly bundles all dependencies and files together so that you could easily distribute them. The size is usually large as it bundles all dependencies , share libraries , packages along with your script file. In most cases, it will be difficult to reduce the size.

How ever, you can ensure the following so that there is lesser cruft in the bundled application.

  • Do not use --no-strip option, this will ensure that debug symbols are stripped.
  • Use "--optimize 2 or -O2" optimization option
  • Use "--strip (-S)" option to strip debug and local symbols from output
  • Use "--debug-skip-macholib", it will not make it truly stand alone but will reduce the size
  • I am hoping that you have removed unnecessary files from wxPython like demo, doc etc.
pyfunc
It's the wxPython part that confuses me. Does py2app include the entire `wx` package? Can I tell it only to take specific parts? I only use a small fraction of the package so that would save a lot of space if possible...
c00kiemonster
@c00kiemonster: Since this is wrapper over c files. I guess the libs will be all loaded and packaged. I don't think you could strip that.
pyfunc
A: 

This is a workaround.

It will depend on which OS you want to target. Python and wxPython are bundled with every Mac OS X installation (at least starting with Leopard, if I recall correctly)

What you might try, is to add the --alias compilation option. According to the py2app doc:

Alias mode (the -A or --alias option) instructs py2app to build an application bundle that uses your source and data files in-place.

So that the app will try to use the Mac OS X version of wxPython.

CAREFUL
The alias option is called development mode.

If you use another library that is not bundled with Mac OS X, it won't work.
If you want to port your application to Windows or Linux, it won't work.

I've had some successful use with this method but in the end, went back to zipping a 30/40MB file. Which in the end is not that big.

Loïc Wolff
Yea it is an option to use in-place libraries instead. Will give it a try.
c00kiemonster