[Python] Reducing size of pyinstaller exe

Discussão em 'Python' iniciado por Stack, Dezembro 1, 2024.

  1. Stack

    Stack Membro Participativo

    I have a simple pandas pyinstaller exe which is over 40MB.

    My exe example:

    import collections
    import csv
    import selenium
    import pandas

    print('hi')


    40MB+ for this seems a bit overkill.

    How can I reduce this as much as possible?

    One method:

    pyinstaller --onefile --exclude matplotlib --exclude scipy --exclude pandas --exclude numpy.py


    This however is not practical considering how big the exclusion list would be.

    How do I select a folder for pyinstaller to get modules from and exclude everything else so I may have a small application?

    Spec file:

    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 )


    It's also worth mentioning. By default, Pyinstaller does not detect pandas.

    Add:

    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.

    Continue reading...

Compartilhe esta Página