I tried to figure out how to get py2exe to handle errors more elegantly. Two strange things basically happen:
1) A pop-up message after turning off the program => you need to disable (do not show) this pop-up window
- Use try / except => does not work
2) Creating a log file created in c: \ Program Files \ AppName \ AppName.exe.log (sometimes with write permissions to this folder) => redirect the log to c: \ ProgramData p>
- Use sys.stdout and sys.stderr => not working
I think I can just put the code in the wrong place, and the py2exe bootstrap code runs AFTER I installed them, but I'm not sure. I tried putting this code right before I generated the error log, but it still goes where py2exe loads them (StdErr objects)
The structure of my program is as follows
src/ python/ gui/ __main__.py
Basic .py
if __name__ == "__main__": # Redirect py2exe log to somewhere else if windows if hasattr(sys,"frozen") and sys.frozen in ("windows_exe", "console_exe"): stdout_file = "c:\ProgramData\AppName\out.log" stderr_file = "c:\ProgramData\AppName\err.log" sys.stdout = open(stdout_file, "w") sys.stderr = open(stderr_file, "w") try: gui = AppNameGui() gui.main() except: traceback.print_exc()
source share