Slim down Python wxPython OS X app built with py2app?

Question:

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?

Asked By: c00kiemonster

||

Answers:

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.
Answered By: pyfunc

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.

Answered By: Loïc Wolff

I tried doing like this: python setup.py py2app -O2 -S
as advised from above by pyfunc
My file against the background of the standard python setup.py py2app
decreased by exactly 1MB, from 85MB to 84MB.

Apart from the first attempt, I tested this variant of python setup.py py2app --debug-skip-macholib
result 83.5 MB.

Сonclusion: this does not greatly affect the file size, and whether it will work if all the tips are applied, I can not be sure of this.

the maximum removal of unnecessary data will give the result -2.5MB.

a drop in the sea

-But I am grateful for the recommendations, it was interesting to know!

Answered By: Valerij