Improve Python (.exe) startup time
I created an exe with the PyInstaller. As soon as I enable the --onefile flag. The exe needs several minutes to start. When I build the application with the --onedir flag, the exe launches immediately after launch. In order to distribute the application better, it is important for me that the exe is created with the --onefile flag.
My problem can be reproduced with the following two scripts.
In main.py I only import the torch module, because the problems only occur with this module.
#main.py
print(&quot;Test1&quot;)
import torch
print(&quot;Test2&quot;)
print(torch.cuda.is_available())
print(&quot;Test3&quot;)

I generate the exe with the setup.py file.
#setup.py
import PyInstaller.__main__
import pyinstaller_versionfile

PyInstaller.__main__.run([
    'main.py',
    '--onefile',
    '--name=Object Detection',
    '--console',
])

Alternatively, the exe can also be generated using the Powershell command.
pyinstaller --noconfirm --onefile --console --name &quot;Object Detection&quot;

So my question is what can be done to make the application start faster? What is the specific cause of the problem?
By excluding the module --exclude-module=torch the application also starts immediately,
but that's not my goal.

Pyinstaller --onefile mode has to unpack all libraries before starting in a temporary directory, when you use --onedir they are already there. The problem is noticeable with big libraries like PyTorch ...
