-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_launcher.py
More file actions
132 lines (108 loc) · 4.28 KB
/
debug_launcher.py
File metadata and controls
132 lines (108 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os
import sys
import traceback
import time
# Save the original excepthook
original_excepthook = sys.excepthook
def exception_hook(exc_type, exc_value, exc_traceback):
"""
Custom exception handler that writes errors to a file
and keeps the console window open
"""
# First call the original exception hook
original_excepthook(exc_type, exc_value, exc_traceback)
# Write the error to a log file
with open('error_log.txt', 'a') as f:
f.write(f"\n\n--- Error at {time.strftime('%Y-%m-%d %H:%M:%S')} ---\n")
traceback.print_exception(exc_type, exc_value, exc_traceback, file=f)
# Keep the console window open
print("\nApplication crashed. Error has been logged to error_log.txt")
print("Press Enter to exit...")
input()
# Set the custom exception hook
sys.excepthook = exception_hook
# Try to import and run the main application
try:
# Path setup for PyInstaller bundled app
if getattr(sys, 'frozen', False):
# If we're running as a bundled exe, use the sys._MEIPASS path
bundle_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
os.chdir(bundle_dir)
print(f"Running from bundle directory: {bundle_dir}")
# Add the bundle directory to the system path
if bundle_dir not in sys.path:
sys.path.insert(0, bundle_dir)
# Print information that could help with debugging
print("Python version:", sys.version)
print("Platform:", sys.platform)
print("Current working directory:", os.getcwd())
print("System path:", sys.path)
# Try to import critical components
print("\nImporting critical components...")
try:
import PySide6
print("PySide6 loaded successfully")
print("PySide6 version:", PySide6.__version__)
print("PySide6 location:", PySide6.__file__)
# Test specific PySide6 imports
from PySide6 import QtWidgets, QtCore
print("QtWidgets and QtCore loaded successfully")
from PySide6 import QtWebEngineWidgets
print("QtWebEngineWidgets loaded successfully")
except ImportError as e:
print(f"Failed to import PySide6 components: {e}")
try:
from Custom_Widgets import *
print("Custom_Widgets loaded successfully")
except ImportError as e:
print(f"Failed to import Custom_Widgets: {e}")
try:
import sklearn
print("sklearn loaded successfully")
print("sklearn version:", sklearn.__version__)
except ImportError as e:
print(f"Failed to import sklearn: {e}")
try:
import numpy
print("numpy loaded successfully")
except ImportError as e:
print(f"Failed to import numpy: {e}")
try:
import pandas
print("pandas loaded successfully")
except ImportError as e:
print(f"Failed to import pandas: {e}")
# Try to import the main application
print("\nImporting main application...")
try:
from main import MainWindow
print("MainWindow class loaded successfully")
except ImportError as e:
print(f"Failed to import MainWindow: {e}")
raise
# Try to create the QApplication
print("\nCreating QApplication...")
app = QtWidgets.QApplication(sys.argv)
print("QApplication created successfully")
# Important: Enable QWebEngineView debugging
os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = "9222"
# Try to create the main window
print("\nCreating main window...")
window = MainWindow()
print("Main window created successfully")
# Show the window
print("\nShowing main window...")
window.show()
print("Main window shown successfully")
# Run the application
print("\nRunning application event loop...")
sys.exit(app.exec())
except Exception as e:
print(f"\nFATAL ERROR: {e}")
traceback.print_exc()
# Write to error log
with open('error_log.txt', 'a') as f:
f.write(f"\n\n--- Fatal Error at {time.strftime('%Y-%m-%d %H:%M:%S')} ---\n")
traceback.print_exc(file=f)
print("\nPress Enter to exit...")
input()