0

I am looking for a way to reduce unnecessary modules from a script that uses pandas and that is converted to an exe file with pyinstaller.

The script uses the following imports:

from pandas import read_excel
from os import chdir, makedirs
from os.path import isfile, abspath, join, isdir, dirname
from glob import glob
from pathlib import Path as P
import argparse

So, basically "all I need" from pandas is to read an Excel file and to export it into another Excel file and CSV file. The file blows up to around 200MB, mainly due to Pandas. Pandas again needs xlrd and openpyxl to process the Excel files.

It is possible to exclude modules from the file that are not required by running e.g.:

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

I wonder what else I could remove to make the resulting file smaller? Are there any further big modules that I could exclude to produce a minimal Excel converter?

I am using Pandas because it is convenient. One option I guess would be to not use it but to use openpyxl and csv instead.

Soerendip
  • 7,684
  • 15
  • 61
  • 128
  • Yah, I would recommend re-writing your script to use one of the Excel specific libraries. You'll have to exclude quite a few packages from Pandas! – mgrollins Sep 06 '19 at 22:57
  • 1
    That is what I did. Now, the file is 7MB instead of 200. – Soerendip Sep 06 '19 at 23:54
  • [Python: Excluding Modules PyInstaller](https://stackoverflow.com/q/4890159/7306999) – Xukrao Sep 06 '19 at 23:57
  • Thanks Kukrao, the question is more about which modules might be excluded rather than how. – Soerendip Sep 07 '19 at 00:00
  • Another general tip is to create a python environment that contains only the absolutely needed packages for your script (e.g. with [vitualenv](https://virtualenv.pypa.io) or [conda](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html)), and then run pyinstaller within this environment. – Xukrao Sep 07 '19 at 00:06
  • Nice! Pandas is such a heavy, batteries-included package I think this is the way to go! – mgrollins Sep 07 '19 at 00:17

0 Answers0