gpt4 book ai didi

python - 如何使用 cx_freeze 制作可执行文件以及如何减小生成的可执行文件的大小

转载 作者:行者123 更新时间:2023-12-04 10:15:01 27 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How to reduce cx_Freeze compiled Python executable size?

(1 个回答)


去年关闭。




我制作了一个 python 脚本,现在我想用 cx_freeze 使其可执行。这对我来说是第一次。

我的代码:

    from cx_Freeze import setup, Executable


build_exe_options = {'packages': ['pandas','os']}


setup(
name = "monprog",
version = "0.1",
options = {"build_exe": build_exe_options},
description = "Convert_program",
executables = [Executable("test.py")],
)

它有效,但我的文件太大(2GB)。许多库文件(150 - 200 个库)被导入到可执行帮助程序中。

我的程序很简单,有 2 个导入(pandas 和 os)和 50 行代码。也许“选项”参数有误?

如何减小程序大小?

谢谢`

PS:我使用anaconda平台

最佳答案

逐字取自 here :

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.

关于python - 如何使用 cx_freeze 制作可执行文件以及如何减小生成的可执行文件的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61106637/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com