减少pyinstaller exe的大小 [英] Reducing size of pyinstaller exe
问题描述
我有一个简单的pandas pyinstaller exe,它的大小超过40MB.
I have a simple pandas pyinstaller exe which is over 40MB.
我的exe示例:
import collections
import csv
import selenium
import pandas
print('hi')
40MB +似乎有点过分了.
40MB+ for this seems a bit overkill.
如何尽可能减少这种情况?
How can I reduce this as much as possible?
一种方法:
pyinstaller --onefile --exclude matplotlib --exclude scipy --exclude pandas --exclude numpy.py
但是考虑到排除列表有多大,这是不切实际的.
This however is not practical considering how big the exclusion list would be.
如何为pyinstaller选择一个文件夹,以从中获取模块并排除其他所有内容,所以我的应用程序可能很小?
How do I select a folder for pyinstaller to get modules from and exclude everything else so I may have a small application?
规范文件:
a = Analysis(['123.py'],
pathex=['C:\\Users\\AA\\ZZ'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='123',
debug=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
这也值得一提.默认情况下,Pyinstaller不会检测到熊猫.
It's also worth mentioning. By default, Pyinstaller does not detect pandas.
添加:
hiddenimports = ['pandas._libs.tslibs.timedeltas']
To: C:\Users\<NAME>\AppData\Local\Programs\Python\Python36\Lib\site-packages\PyInstaller\hooks
使用多个可执行文件时,可能的解决方案将每个可执行文件链接到一个单独的文件夹或具有所有导入的可执行文件.
A possible solution when using multiple executables, could be to link each executable to a separate folder or executable with all imports.
推荐答案
尝试使用virtualenv设置环境,然后仅在其中安装所需的库
try setting up your environment with a virtualenv, and install in there only the required libraries
有关使用虚拟环境的一些详细信息,请参见: https://virtualenv.pypa.io/en /stable/
some details on working with virtual env are here: https://virtualenv.pypa.io/en/stable/
这篇关于减少pyinstaller exe的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!