减少Pyinstaller生成的可执行文件的文件大小的一些常规技巧 [英] What are some general tips to reduce the file size for a Pyinstaller generated executable

查看:160
本文介绍了减少Pyinstaller生成的可执行文件的文件大小的一些常规技巧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Pyinstaller将python脚本转换为可执行文件,该脚本包含从nltk,begin,json和其他四个软件包中的多个导入.生成的10行代码的可执行文件为54MB,这实在是太高了,我知道它将所有模块打包在一个文件中,但是它的确如此之大,因为python脚本本身只有2KB.

I am using Pyinstaller to convert a python script to an executable, the script contains multiple imports from various packages like nltk,begin,json and four more. The resulting executable file for a 10 line code is 54MB which is unrealistically high, I know it packages all modules in a single file , but does it make it so large as the python script itself is only 2KB.

减小".exe"文件大小的一些常规技巧是什么?

What are some general tips to reduce the ".exe" file size?

我正在使用下面的命令来转换脚本

I am using the command below to convert the script

>pyinstaller.py  -F  -o output check.py

我只导入了单个功能,而没有导入整个模块,例如:

I have only imported individual functions and not entire modules, like:

from nltk.metrics.agreement import AnnotationTask

导入的模块具有独立的功能,我仅选择性地导入了3-4个功能,但这似乎对生成的exe文件大小没有任何影响,所有功能都浪费在exe文件中吗?如何避免这种情况?

The imported modules have independent functions and I have selectively imported only 3-4 functions , but this does not seem to have any effect on the generated exe file size, do all functions wastefully get imported in the exe file? How to avoid this?

推荐答案

您正在比较两个完全不同的事物,您生成的exe文件不仅包含您的文件,还包含Python解释器和所有导入的模块.查看在Windows下安装的python 2.7,我发现它的大小为83 MB. ntlk和co可能都不是最小的库,您必须以一种或另一种方式将它们全部包含在可执行文件中.为了进行比较,我的一个中小型项目使用cx_freeze(包括10 MB的QT4 dll)生成了约23 MB,因此您可以尝试使用.

You are comparing two totally different things, the exe file you generate does not only contain your file but also the Python interpreter and all imported modules. Looking at my python 2.7 install under windows I see that it is 83 MB large. ntlk and co probably aren't the smallest libraries either and you have to include all of them in the executable one way or the other. For comparison a medium-smallish project of mine generates about 23 MB using cx_freeze (and that includes 10 MB of QT4 dlls), so you could try that.

您还可以使用UPX压缩可执行文件,如

Also you can compress the executable using UPX, as described here which may help.

这篇关于减少Pyinstaller生成的可执行文件的文件大小的一些常规技巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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