为什么我的exe脚本如此繁重? (Pyinstaller)

时间:2019-10-31 13:34:42

标签: python pyinstaller

我使用的库:

import os, sys
import subprocess
import shutil
from docx import *
from django.utils.encoding import smart_text
import xlrd
from pdfminer import *
import textract
import pandas as pd
from pptx import Presentation
from tika import parser

如何减小exe大小?我的规格文件:

a = Analysis(['tryhard.py'],
             pathex=['C:\\poppler-0.67.0\\bin'],
             binaries=[],
             datas=[],
             hiddenimports=['textract.parsers.txt_parser', 'textract.parsers.pdf_parser', 'textract.parsers.docx_parser', 'textract.parsers.odt_parser', 'pandas._libs.tslibs.timedeltas'],
             hookspath=[],
             runtime_hooks=[],
             excludes=['numpy'],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

命令pyinstaller -F --clean --onedir myspecfile.spec生成3个4GB的文件夹。

1 个答案:

答案 0 :(得分:1)

在生成的文件夹中查找不需要的内容,然后在spec文件的excludes行中指定它们。例如,我不使用Tcl,Tk或Tkinter,所以我的excludes如下:

excludes=['FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter'],

Pyinstaller包括厨房水槽,以防万一。可以使用excludes排除不需要的所有内容。这样可以减小大小(我的单文件应用程序最终大小为63MB)。

Here是关于excludes的类似问题。