如何压缩 python .exe 文件大小

发布于 2025-01-15 23:31:31 字数 172 浏览 2 评论 0原文

我已使用 this 将 python 文件转换为 exe 但是.exe的大小是800mb,有什么办法可以减少它的大小吗?

I have converted python file to exe using this
But the size of .exe is 800mb, is there any way I can reduce its size?

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

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

发布评论

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

评论(1

季末如歌 2025-01-22 23:31:31

使用 Pyinstaller

pyinstaller 的 --onefile 标志(例如,pyinstaller myprogram.py --onefilepyinstaller myprogram.py -F 将所有内容放入一个可执行文件中,包括所有已安装依赖项的所有代码,即使您只使用其中的一个函数。

--onedir 或。 -D 标志将这些依赖项放在与编译代码一起打包的目录中,它往往会大大减少 .exe 文件的大小

但是,我仍然不建议使用。 Pyinstaller。经过广泛的实验,我发现在尚未具备 Python 友好环境的计算机上执行时间非常慢(大部分执行时间缓慢来自于加载这些依赖项。)

使用cx_Freeze

对于我为我的部门构建的可执行文件,我使用 cx_Freeze 构建安装程序或磁盘映像。

为此,您所要做的就是编写安装脚本然后调用 py setup.py bdist_msi (Windows) 或 py setup.py dbist_dmg (Linux)。

生成的安装程序相对较小,并且一旦安装,它将比我见过的任何 Pyinstaller 选项执行得快得多。

Using Pyinstaller

The --onefile flag with pyinstaller (e.g., pyinstaller myprogram.py --onefile or pyinstaller myprogram.py -F puts everything in just a single executable, including all the code of all your installed dependencies, even if you're using just one function from them. That's a lot!

The --onedir or -D flag instead puts the those dependencies in a directory that's packaged alongside your compiled code. It tends to reduce the size of the .exe file considerably.

But still, I wouldn't recommend using Pyinstaller. Having experimented with it extensively, I've found that execution time is incredibly slow on machines that don't already have a Python-friendly environment. (Most of the slow execution time comes from loading those dependencies.)

Using cx_Freeze

For the executables that I build for my department, I use cx_Freeze to build an installer or a disk image.

To do so, all you have to do is write a setup script and then call py setup.py bdist_msi (Windows) or py setup.py dbist_dmg (Linux).

The resulting installer will be relatively small and, once it's installed, it will execute much faster than any of the Pyinstaller options I've seen.

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