简体   繁体   English

Python3编译的应用程序是否使用zip减小大小?

[英]Python3 compiled App Decrease Size with zip?

I have compiled with success a rather big app ,but the size of the app is way too big(about 1 GB).I realized that almost the half (400MB) was taken from just 2 modules(PyQt5 and mpl_toolkits(basemap)).Of course the one approach is to delete the side-services you dont need but i cant in my case as i use about all of these in my app. 我已经成功编译了一个相当大的应用程序,但是该应用程序的大小太大了(约1 GB)。我意识到几乎一半的内容(400 MB)仅来自2个模块(PyQt5和mpl_toolkits(basemap))。当然,一种方法是删除不需要的辅助服务,但是我无法使用,因为我在我的应用程序中使用了所有这些服务。 Then i was thinking about ziping these modules but i don't know if this is safe or execute time viable. 然后我在考虑压缩这些模块,但我不知道这是否安全或执行时间是否可行。 So is there a suficient way to minimize the size of my app, and if the ZIP is the only answer is it viable to do this on a lib such PyQt5 witch is imported many times in my script? 因此,有没有足够的方法来最小化我的应用程序大小,并且如果ZIP是唯一的答案,那么是否可以在这样的库中执行此操作,例如在我的脚本中多次导入PyQt5女巫?

It is entirely possible to do this; 完全有可能做到这一点; Python has always supported "zipapps", and as of 3.5, provides a module, zipapp , to assist with creating them . Python一直支持“ zipapps”,从3.5版本开始,它提供了一个模块zipapp来帮助创建它们

The only concern is whether your dependencies run properly zipped; 唯一的问题是您的依赖项是否正确压缩了; most do, but some take file-system layer dependencies that zipping (and eggs and the like) don't handle (the setup.py file for these would declare zip_safe=False to tell tools not to allow it). 大多数都可以,但是有些文件系统依赖于压缩(以及鸡蛋等)无法处理的文件系统层依赖性(这些文件的setup.py文件将声明zip_safe=False来告诉工具不允许这样做)。 Packages with C extensions would have to assert zip_safe=True , as the default analyzer assumes C extensions can't be safely zipped (though many can) . 具有C扩展名的软件包必须断言zip_safe=True ,因为默认分析器假定无法安全压缩C扩展名(尽管很多可以)

It will slow down startup a bit (since it has to decompress the modules), but it shouldn't dramatically slow runtime, no matter how many times you import it; 它会稍微降低启动速度(因为它必须解压缩模块),但是无论您导入多少次,都不应显着降低运行时间。 the first import is the only one that really matters, since subsequent imports just pull the cached copy of the module from an internal cache ( sys.modules ). 第一次导入才是真正重要的操作,因为后续导入只是从内部缓存( sys.modules )中提取模块的缓存副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM