App created with PyInstaller has a slow startup

前端 未结 6 2208
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 15:32

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

相关标签:
6条回答
  • 2020-12-04 15:58

    For my application, the long startup time almost entirely was caused by the antivirus system. Switching it off reduced the startup in my case from 3 minutes to less than 10secs!

    To bring these measurements into perspective: My application was bundled with extra data files (about 150 files with a payload of 250MB), besides carrying around Qt and numpy (that may depend on Intel MKL, which alone adds another 200MB to the bundle!) dependencies. It even didn't help much that the tested system was running with a solid state drive...

    In conclusion: if you have a large application with lots of dependencies, the startup time may be affected strongly by the antivirus system!

    0 讨论(0)
  • 2020-12-04 16:02

    In case anyone is still have this issue, I resolved mine by running the exe locally and not on any sharedrives. This took the startup time from over a minute to under 10 seconds.

    0 讨论(0)
  • 2020-12-04 16:04

    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?

    0 讨论(0)
  • 2020-12-04 16:08

    Tell PyInstaller to create a console-mode executable. This gives you a working console you can use for debugging.

    At the top of your main script, even before the first import is run, add a print "Python Code starting". Then run your packaged executable from the command line. This way you can get a clear picture whether the time is spent in PyInstaller's bootloader or in your application.

    PyInstaller's bootloader is usually quite fast in one-dir mode, but it can be much slower in one-file mode, because it depacks everything into a temporary directory. On Windows, I/O is very slow, and then you have antiviruses that will want to double check all those DLL files.

    PyQt itself is a non-issue. PyQt is generated by SIP which generates very fast lazy bindings; importing the whole PyQt is faster than any other GUI library because it basically does nothing: all bindings to classes/functions are dynamically created when (and if!) you access them, saving lots of memory too.

    If your application is slow at coming up, that will be true without PyInstaller as well. In that case, your only solution is either a splash screen (import just PyQt, create QApplication, create a display the splashscreen, then import the rest of your program and run it), or rework your code. I can't help you much without details.

    0 讨论(0)
  • 2020-12-04 16:16

    I agree with above answers. My Qt python program needed about 5 seconds to start up on a decent PC when using onefile mode. After I change to --onedir, it only took around one second to start; almost immediately after user double clicks the exe file. But the drawback is that there are many files in that directory which is not so neat.

    0 讨论(0)
  • 2020-12-04 16:18

    I have 'compiled' a few wxPython apps using py2exe and cx_Freeze, None of them take more than 4 seconds to start.

    • Are you sure sure it's not your code ? maybe some network or some I/O resource call holding your app ?
    • Have you tried other machine than yours? Even the fastest hardware can be slow sometimes with the wrong software config, apps or OS, try it.
    • Try timing it with timeit module.

    I never used pyQT, but with wxPython the startup speed is OK, and after the first initialize if I close and open again, it's faster than the first time.

    0 讨论(0)
提交回复
热议问题