Reputation: 21
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("Test1")
import torch
print("Test2")
print(torch.cuda.is_available())
print("Test3")
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 "Object Detection"
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.
Upvotes: 1
Views: 744
Reputation: 247
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 ...
Upvotes: 3