Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

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

1 Answer

0 votes
by (62.9k points)

For me, it was a simple case of using pandas were the size of the exe file is going to be huge.

Though removing certain directories was helpful, as it was UPXING that helped a lot too.

So there was an attribute that did all this, but for now, there is some manual handling involved because: multipackage-bundles is broken.

 

Now to the straightforward answer for various executables. If you have a lot of executable files, I highly recommend this approach:

pyinstaller -F abc.py --onedir (Contains all imports of both scripts)

pyinstaller -F abd.py --onedir (Contains all imports of both scripts)

Now place abd.exe in one directory of the abc.py folder as well as any other external scripts.

Browse Categories

...