In this tutorial we will present several solutions to a common issue where the Pyinstaller Console window closes too quickly, or immediately after you click on the EXE.
Using a separate Console Window
First and foremost, there is a good chance that there is an error that is causing this problem. There can be several reasons for this. Even if your application runs smoothly as a .py
file, there are other possible issues that can other during the compellation process which can crash your application.
For example, if you incorrectly configured your file paths, or forgot to include a certain file (like an image) into the EXE, then it will crash.
An easy way of finding out whether there is an error occurring within your code, is to use run the program on the command prompt / terminal.
On whatever Operating system you are using, open up your respective Console window, and navigate to the directory where your EXE is. Then run the following command (which is just the name of your exe).
C:\Users\CodersLegacy\output> application.exe
Windows PowerShell users will have to use the following format instead:
C:\Users\CodersLegacy\output> ./application.exe
This will run and execute the code. If there is an error in the program, the error will be displayed on the console window you are running this command on. Once you know the problem, you can begin on solving it.
It will not crash and shutdown unlike the console which shows up (briefly) when you click the EXE. Here is a example where we deliberately ran some erroneous code.

If there is no error shown, then that means everything is ok. The problem you are facing is most likely the one we will discuss in the next section.
Pyinstaller console window closes upon completion
It is the default nature of the console window that shows up, to close once it has completed it has execution (the last line of code has been executed successfully). Often the window executes the code quickly (especially when the code is small) and the program closes before we get the chance to see the output.
To resolve this problem, and an ‘input()’ function at the very bottom of your code. This will cause the window to always wait for the user to enter something before exiting. Only after you press a key (like enter) will the program quit.
e.g.
# Imports
# Code
# More Code
block = input()
There are other variations that you can use to prevent this from happening. For example, you can add a infinite while loop. Though that could cause your code to hang, so be careful.
Broken Pyinstaller version
If the two above fixes do not work, you should try updating or reinstalling your Pyinstaller version. It is possible that your installation got corrupted, or is a old version missing some essential updates.
This marks the end of the “Pyinstaller Console window closes immediately with solutions” Tutorial. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the tutorial content can be asked in the comments section below.