I have a Pyinstaller one-directory executable that is saved on a shared B: drive that other people have access to. The executable starts up quickly but takes a long time to load all of the modules (about 30-50 seconds). When I run the executable locally on my C: drive, it takes only about 5 seconds to load everything. The program runs fine/quickly on both the C: drive and shared B: drive after the initial import of modules, so I have narrowed the problem down to this. I even took advice from this post on adding an initial "Splash" image screen. I wrapped this image around my import code chunk, this is how I determined that the program is starting quickly but the hang-up is on the import module part. Is there any way to pre-import/load these modules, maybe in a separate .py file, and then later load them into the executable? Maybe have the pre-load code constantly running and then inherit the modules from it?
The main culprits are Matplotlib, Seaborn, OpenPyxl, and Pandas. I am importing them as import pandas as pd
, import matplotlib.pyplot as plt
, etc" and the method of individually importing what I need (e.g. from pandas import DataFrame
, etc.) is not feasible. The executable is created with: pyinstaller --windowed --icon="Icon.ico" Program.py
. The program is mainly PySimpleGUI but, like stately previously, it isn't the GUI part that is taking long to load. This is on a Windows-10 machine.
Any hints on speeding up the import process are appreciated.
The best answer I could find was to just create a smaller onefile executable (or one directory) by creating a virtual environment then running pyinstaller from that environment. Follow the advice in esperluette's response for a comprehensive, easy to follow solution.