-2

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 !

Duke Nukem
  • 319
  • 4
  • 15
  • Do you mean that the `.EXE` file created using the pyinstaller, generates an error upon execution? OR do you mean that during the process of building the `.EXE` with the pyinstaller, you are getting the mentioned error? – ρss Nov 03 '15 at 13:22
  • It's during the runtime. of the .EXE. When an exception occurs during the runtime, this window show up...but I don't want this appears. – Duke Nukem Nov 03 '15 at 14:58
  • Then I think you have to edit the python code. In the code there must be a place where this exception is configured... find it and modify the exception. – ρss Nov 03 '15 at 15:13
  • Do you mean catch this exception? I know I can do it, but I wanted to know if it is also possible to hide error window after using pyinstaller – Duke Nukem Nov 03 '15 at 15:17
  • I think it is not possible to hide this window after the executable is built. You have to modify the code, then build the executable again. – ρss Nov 03 '15 at 15:20

2 Answers2

4

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.

codewarrior
  • 2,000
  • 14
  • 14
0

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)
Community
  • 1
  • 1