精简使用 py2app 构建的 Python wxPython OS X 应用程序?

发布于 2024-09-28 18:03:06 字数 98 浏览 0 评论 0原文

我刚刚使用 py2app 制作了一个 Python wxPython 脚本的小应用程序。一切都如广告所示,但该应用程序的尺寸相当大。有没有办法优化 py2app 让应用程序体积更小?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

几味少女 2024-10-05 18:03:06

这是一种解决方法。

这取决于您想要定位的操作系统。 Python 和 wxPython 与每个 Mac OS X 安装捆绑在一起(至少从 Leopard 开始,如果我没记错的话)

您可能会尝试添加 --alias 编译选项。根据 py2app 文档 :

别名模式(-A 或 --alias 选项)指示 py2app 构建就地使用源文件和数据文件的应用程序包。

这样应用程序就会尝试使用 Mac OS X 版本的 wxPython。

小心
别名选项称为开发模式

如果您使用未与 Mac OS X 捆绑的其他库,它将无法工作
如果您想将应用程序移植到 Windows 或 Linux,它不会工作

我已经成功地使用了这种方法,但最终还是回到了压缩 30/40MB 文件。最终没有那么大。

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.

白色秋天 2024-10-05 18:03:06

py2app 或任何其他此类打包器主要将所有依赖项和文件捆绑在一起,以便您可以轻松分发它们。它的大小通常很大,因为它捆绑了所有依赖项、共享库、包以及脚本文件。在大多数情况下,减小尺寸是很困难的。

但是,您可以确保以下事项,以便减少捆绑应用程序中的麻烦。

  • 不要使用 --no-strip 选项,这将确保删除调试符号。
  • 使用“--optimize 2或-O2”优化选项
  • 使用“--strip (-S)”选项从输出中去除调试和本地符号
  • 使用“--debug-skip-macholib”,它不会使其真正独立但会减少大小
  • 我希望你已经从 wxPython 中删除了不必要的文件,如演示、文档等。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文