python 可执行文件大_如何减少cx_Freeze编译的Python可执行文件的大小?

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?

解决方案

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:

end user should be able to run executable on essentially any Windows machine, including possibly one without Python, numpy, and matplotlib

distributed binary size should be small

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值