Python – App created with PyInstaller has a slow startup

performancepyinstallerpythonwindows

I have an application written in Python and 'compiled' with PyInstaller. It also uses PyQt for the GUI framework.

Running this application has a delay of about 10 seconds before the main window loads and is shown. As far as I can tell, this is not due to slowness in my code. Instead, I suspect this is due to the Python runtime initializing.

The problem is that this application is started with a custom laucncher / taskbar application. The user will click the button to launch the app, see nothing appear to happen, and click elsewhere on another application. When my application shows it's window, it cannot come to the foreground due to the rules for SetForegroundWindow.

I have access to the source for the PyInstaller win32 loader, the Python code, and even the launcher code.

My questions are:

  • How can I make this application start faster?

  • How can I measure the time spend i the first few seconds of the process's lifetime?

  • What is the generally accepted technique for reducing time until the first window is shown?

I'd like to avoid adding a splash screen for two reasons – one, I expect it won't help (the overhead is before Python code runs) and two, I just don't like splash screens 🙂

If I need to, I could probably edit the PyInstaller loader stub to create a window, but that's another route i'd rather not take.

Best Answer

I suspect that you're using pyinstaller's "one file" mode -- this mode means that it has to unpack all of the libraries to a temporary directory before the app can start. In the case of Qt, these libraries are quite large and take a few seconds to decompress. Try using the "one directory" mode and see if that helps?