Frage

I have quite a 'heavy' python program that I would like compiled to an exe.

The program has a decent amount of imports, but using the PyQT4 framework, I load these imports whilst a splashscreen is visible.
I compile this program to a single .exe file, using pyinstaller (in cmd):

python %pycompile_file% --onefile --noconsole --icon=Icon.ico Script.pyw

However, even though the splashscreen is set to show whilst a significant amount of modules are imported (notably including sympy), and even though it shows instantly and for an adequate time frame when ran through python;
Running the produced .exe results in a serious delay before the splashscreen shows, which is only shown for a very short time before the whole program is loaded.

My suspicion is that compiling from .pyw to .exe has sped the actual 'code' up (hence why the splashscreen in shorter), but slows the actual 'beginning' of the program's execution.

How can I fix this so that the .exe does not 'start so slowly'?

(I suspect compiling to --onefile contributes greatly, but I need the .exe file to be one folder up from all the .dlls and I can not figure out how to make pyinstaller do this)

Thanks!


Windows 7
python 2.7.2
pyinstaller
PyQt4

War es hilfreich?

Lösung 2

Solved;

Do not archive the .dlls into the compiled .exe.
Keep all the files imported by the code (which you wish for the User to interact with without navigating through .dlls) one level up, and create a shortcut to the .exe that has a working directory one up from the .exe.

You can make such a shortcut using pywin32.

Andere Tipps

Pyinstaller doesn't turn python code into native code, it just packs the python bytecode and the bytecode interpreter into a single file - once start-up overheads are out of the way, actual processing will happen at exactly the same speed.

Pyinstaller's --onefile mode will make your app slower to start up, because it has to unpack all the libraries into a temporary directory before it can load them. In the case of PyQT, these libraries are fairly large so the delay will be noticable. Using one-directory mode, so that the DLLs don't need unpacking, should be much faster.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top