如何减少cx_Freeze编译的Python可执行文件的大小? [英] How to reduce cx_Freeze compiled Python executable size?

查看:239
本文介绍了如何减少cx_Freeze编译的Python可执行文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用cx_Freeze编译了Python程序. Python代码本身只有195行.但是,我的编译程序是 500 MB .我使用matplotlibnumpypymsgbox,但我不知道我的库是否会对编译后的程序大小产生太大影响.

I've compiled a Python program with cx_Freeze. The Python code itself is only 195 lines long. However, my compiled program is 500 MB. I use matplotlib, numpy, and pymsgbox and I don't know if my libraries affect my compiled program size that much.

文件大小异常的原因是什么,有没有办法减小我的可执行文件的大小?

What is the reason for this unexpected file size and is there a way to reduce the size of my executable?

推荐答案

cx_Freeze的部分目的是捆绑所有依赖项,以便最终用户无需安装它们. numpymatplotlib等不是很小的依赖项,尤其是因为它们具有大的二进制(非Python)组件.因此,您要问的是物理上不可能的,不是因为cx_Freeze的限制,而是因为以下两个要求之间的矛盾:

Part of the purpose of cx_Freeze is to bundle all the dependencies, so that the end user need not install them. numpy, matplotlib, etc. are not small dependencies, especially because they have large binary (non-Python) components. So what you are asking is not physically possible, not because of cx_Freeze limitations, but because of a contradiction between the following two requirements:

  • 最终用户应该基本上可以在任何Windows计算机上运行可执行文件,包括可能没有Python,numpy和matplotlib的计算机
  • 分布式二进制大小应该小

您不能同时满足这两个要求. cx_Freeze适用于第一个,但不适用于第二个.如果您可以假定最终用户已经安装了Python,numpy,matplotlib(或可以单独安装),并且希望以二进制大小较小的方式分发程序,则更合适.

You cannot satisfy both these requirements simultaneously. cx_Freeze is appropriate for the first, but not the second. If you can assume your end users already have Python, numpy, matplotlib installed (or can install seperately), and want to distribute your program such that the binary size be small, a wheel is more appropriate.

这篇关于如何减少cx_Freeze编译的Python可执行文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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