如何使用py2exe减小exe的大小 [英] how to reduce size of exe using py2exe

查看:167
本文介绍了如何使用py2exe减小exe的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用python和wxwidgets开发了一个小程序.这是一个非常简单的程序,仅在需要时使用一个小型框架来显示一些信息,其余时间则什么也不显示,仅在任务栏中显示一个图标.

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.

当我使用py2exe(单文件exe模式,已优化)构建exe时,我得到了一个6MB的文件!

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

我尝试不包括一些不需要的库或dll,但仍然看不到为什么我只在任务栏中有一个很小的框架和一个图标就得到了这么大的文件.

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.

有什么方法可以减少由py2exe生成的exe的大小?

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'],

谢谢.

推荐答案

程序简单的事实并不意味着它很小.您的程序通过wxWidget堆栈具有许多依赖性,考虑到所有这些,6 Mb看起来并不那么大.

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.

但是,回到问题所在.要收缩py2exe生成的程序,您可以做一些显而易见的事情:

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

  1. 分发更少的东西:看来您已经开始了这条路.查看随程序一起分发的所有内容,并在不需要时将其消除. DllDepend可以告诉您为什么DLL与您的程序一起分发(可能是因为pyd需要它).对于其他模块,请将其删除,然后尝试是否仍可使用...

  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...

更好地压缩它:在每个dll上运行upx.使用7zip最大压缩级别压缩最终程序/归档.

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

这篇关于如何使用py2exe减小exe的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆