为什么我的exe脚本这么重? (Pyinstaller)

问题描述 投票:0回答:1

我使用的库:

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的文件夹。

python pyinstaller
1个回答
1
投票
在生成的文件夹中查找不需要的东西,然后在您的spec文件的excludes行中指定它们。例如,我不使用Tcl,Tk或Tkinter,所以我的excludes看起来像:

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

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

[Here是关于excludes的类似问题。

© www.soinside.com 2019 - 2024. All rights reserved.