Slim down Python wxPython OS X app built with py2app?

一世执手 提交于 2019-12-12 09:16:06

问题


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?


回答1:


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.




回答2:


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.


来源:https://stackoverflow.com/questions/3979658/slim-down-python-wxpython-os-x-app-built-with-py2app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!