简体   繁体   中英

Why is my exe script so heavy? (Pyinstaller)

The libs which I use:

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

What can I do to reduce the exe size? My spec file:

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)

Command pyinstaller -F --clean --onedir myspecfile.spec generates 3 folders with 4GB size.

Look in the generated folders for things you don't need, then specify them in the excludes line of your spec file. For example, I don't use Tcl, Tk or Tkinter, so my excludes looks like:

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

Pyinstaller includes the kitchen sink, just in case. Anything that you can be sure is not needed can be excluded using excludes . That will reduce the size (my final size for a one-file app is 63MB).

Here is a similar question about excludes .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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