After building my exe with pyinstaller, sometimes when an exception occurs, i can see a fatal error in a gui : fatalerror image
I just want to hide this.
ps :I use Pyinstaller with --windowed option
Thanks a lot !
After building my exe with pyinstaller, sometimes when an exception occurs, i can see a fatal error in a gui : fatalerror image
I just want to hide this.
ps :I use Pyinstaller with --windowed option
Thanks a lot !
This dialog is displayed by PyInstaller's startup/shutdown code when your application has an uncaught exception. The best way to suppress it is to catch the exception in your Python code and exit your app normally (by calling sys.exit()
or raising SystemExit
). This could be done with a top-level try...catch
around your main(), or around the call that starts your event loop.
I'd also recommend creating a GUI dialog that displays the traceback for the fatal exception in a text box, to make it easier for users to report the error to you.
I had a similar issue with a root cause involving subprocess.Popen, if you are not using this function (or something similar) then this answer is unlikely to be helpful.
I was having a similar issue trying to build my .exe with pyinstaller. I was using the --noconsole flag as well as the --onefile flag with pyinstaller and was getting the "Fatal Error!" message " returned -1" whenever I tried to execute the resulting .exe file. My .exe would build work with just the --onefile flag but any combination using the --noconsole flag would return the error, leading me to believe it was the source of my issue.
After a little digging I tracked down this answer:
Python subprocess.call() fails when using pythonw.exe
Which seemed to indicate the issue was using pipes when using subprocess.Popen with pythonw.exe instead of python.exe. It seemed logical to me that pyinstaller with the --noconsole flag would use pythonw.exe instead of python.exe when building the .exe leading me to believe this could apply to my issue.
To test this I refactored by code to output the results of my Subprocess.Popen call to a file, then read in and deleted the file. This solved my "Fatal Error!" issue and everything else proceeded to work fine.
Original:
process = subprocess.Popen('cmd /c whoami', stdout=subprocess.PIPE)
user = process.communicate()[0].decode('ascii').strip()
Refactored:
pro = subprocess.Popen('cmd /c whoami > "{0}"'.format(file_name))
pro.wait()
with open(file_name, 'rt') as file:
user = file.read().strip()
os.remove(file_name)