17

I create a single file python application with Pyinstaller using --onefile parameters. Everything work as expected but the startup time is around 10 seconds on my machine. The problems is that during the file unpacking process of Pyinstaller package there are no visual feedback, so you don't know if the application is starting or even if you really clicked the icon. This problem became worse if the machine is slow (on my test with a very old machine i need almost 20 seconds to see the first login of my application) There is a way to create some splash screen or visual feedback (like a progress bar as on unpackers) during the Pyinstaller bootstrap sequence?

Please note the question is about Pyinstaller unpacking process BEFORE the real application will be executed not by the application itself that already has is own splash screen

thank you

19.01.2018 - UPDATE1 My application is FULL GUI so i prefer to not use the console as "visual feedback" during the unpacking process.

Marco
  • 487
  • 2
  • 6
  • 25

5 Answers5

8

There is a beta version of the splash screen!

So just use your normal pyinstaller command in cmd and add:

--splash splashfile.png
djvg
  • 11,722
  • 5
  • 72
  • 103
Fabi0
  • 131
  • 2
  • 5
6

adding --splash splashfile.png gave me high pink color shades on splash screen, so I used JPG image with some colored background and it worked very well.

another update we need to close splash, within our project code in any suitable place feasible for us, else splash screen remains on top of UI until application itself is closed.

        try:
            import pyi_splash
            pyi_splash.update_text('UI Loaded ...')
            pyi_splash.close()
        except:
            pass

and put this splash screen close code with in try block as it is needed only for package execution,
and can just pass on exception and proceed at the time of development runs.

Update:

More elegant way to close the splash screen

if '_PYIBoot_SPLASH' in os.environ and importlib.util.find_spec("pyi_splash"):
    import pyi_splash
    pyi_splash.update_text('UI Loaded ...')
    pyi_splash.close()
    log.info('Splash screen closed.')

reason for discarding try/except because, if you generate console exe then try/except will unnecessarily generates warnings, so to completely avoid warnings also, this can be a good check..

  • import pyi_splash this cant resolved in main code, how can we expect this thing? – Rohithaditya Mar 02 '22 at 14:55
  • @Rohithaditya pyi_splash module will not be resolved in direct source execution, this will be bundled only when you create executable package from pyinstaller.. –  Mar 03 '22 at 18:02
  • I get the error that log is unknown. Where does it belong to, what do I have to define? – Ben Jun 01 '23 at 10:16
  • Instead `log` just use `print` statement if you are not using logger in your project. –  Jun 02 '23 at 15:58
  • Or even just remove that log line, it's just an information. –  Jun 02 '23 at 15:59
4

I have been battling with this problem myself. Unfortunately, there is no feasible solution to the problem other than using the ugly console (completely agree there).

The problem stems from the fact that until PyInstaller unpacks all the files into a temp dir, no scripts will be run. From my research, there is no way to alter this functionality using currently available options within PyInstaller. It would be nice if the community behind PyInstaller would make this a standard feature of the module, but until then we may have to explore other installer options.

Happy programming!

2

One simple solution might be to display the console window after launching the application, which will output the status of the PyInstaller Bootloader while it is being opened.

To display the console, use the --console flag (or edit the .spec file to contain console = True) when bundling your application. These options are documented in the PyInstaller doc file.

apogalacticon
  • 709
  • 1
  • 9
  • 19
  • hi @apogalacticon, currently I already use this solution but is really ugly that in an full GUI application you will see a console. – Marco Jan 19 '18 at 06:05
  • If you added a splash screen to the main.py file in your application (even before most of the import statements), it still would not be displayed until the PyInstaller Bootloader was finished, which takes a considerable amount of time. One way to get around this may be to create a new application, whose only purpose is to display a splash screen and then launch your main application (bundled with pyinstaller) using the python subprocess.run command. – apogalacticon Jan 22 '18 at 18:08
  • Additionally, the application will run faster if it is not bundled using the --onefile flag. Another solution would be to pack your application using [installer creation software](http://www.installsite.org/pages/en/msi/authoring.htm). See this [post](https://stackoverflow.com/questions/5971038/pyinstaller-creates-slow-executable) for a similar discussion. – apogalacticon Jan 22 '18 at 18:10
0

There is a pull request got pyinstaller... Actually, it is already merged into master. It adds this functionality: https://github.com/pyinstaller/pyinstaller/pull/4887

At the moment you will need to build the pyinstaller to have this, but it is feasible. I managed to do this for my project without any deep knowledge in c/c++ etc.

dugwin
  • 31
  • 2