-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_dependencies.py
More file actions
222 lines (190 loc) · 7.6 KB
/
install_dependencies.py
File metadata and controls
222 lines (190 loc) · 7.6 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
"""
IC Authenticator - Dependency Installer
Robust dependency installation with error handling and progress tracking
"""
import sys
import subprocess
import time
from pathlib import Path
# Fix Windows console encoding
if sys.platform == 'win32':
try:
import codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'ignore')
sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'ignore')
except:
pass
def run_pip_command(command, description, retry_count=3):
"""Run pip command with retry logic"""
print(f"\n{'='*60}")
print(f"Installing: {description}")
print(f"{'='*60}")
for attempt in range(retry_count):
try:
if attempt > 0:
print(f"\nRetry attempt {attempt + 1}/{retry_count}...")
time.sleep(2)
result = subprocess.run(
command,
check=True,
capture_output=True,
text=True,
timeout=600 # 10 minute timeout
)
print(f"[OK] {description} installed successfully")
return True
except subprocess.TimeoutExpired:
print(f"[ERROR] Timeout installing {description}")
if attempt < retry_count - 1:
print(" Retrying with longer timeout...")
except subprocess.CalledProcessError as e:
print(f"[ERROR] Error installing {description}:")
print(f" {e.stderr[:500]}") # Print first 500 chars of error
if attempt < retry_count - 1:
print(" Retrying...")
except Exception as e:
print(f"[ERROR] Unexpected error: {str(e)}")
if attempt < retry_count - 1:
print(" Retrying...")
print(f"\n[FAILED] Failed to install {description} after {retry_count} attempts")
return False
def main():
"""Main installation routine"""
print("\n" + "="*60)
print("IC AUTHENTICATOR - DEPENDENCY INSTALLER")
print("="*60)
print("\nThis will install all required dependencies.")
print("Installation may take 10-20 minutes depending on internet speed.")
print("\nPlease be patient and do not close this window.")
print("="*60)
# Get Python executable
python_exe = sys.executable
print(f"\nUsing Python: {python_exe}")
# Check pip
print("\nChecking pip...")
try:
subprocess.run([python_exe, "-m", "pip", "--version"], check=True, capture_output=True)
print("[OK] pip is available")
except:
print("[ERROR] pip not found!")
print("\nPlease ensure Python is installed correctly with pip.")
return False
# Track failures
failed_packages = []
# Step 1: Upgrade pip
if not run_pip_command(
[python_exe, "-m", "pip", "install", "--upgrade", "pip", "setuptools", "wheel"],
"Core Tools (pip, setuptools, wheel)"
):
print("\n[WARNING] Could not upgrade pip, continuing anyway...")
# Step 2: Install NumPy first (many packages depend on it)
if not run_pip_command(
[python_exe, "-m", "pip", "install", "numpy>=1.24.0"],
"NumPy (numerical computing)"
):
failed_packages.append("numpy")
# Step 3: Install OpenCV (headless version - no GUI dependencies)
if not run_pip_command(
[python_exe, "-m", "pip", "install", "opencv-python-headless>=4.8.0"],
"OpenCV (computer vision)"
):
# Try regular opencv-python as fallback
print("\nTrying regular opencv-python as fallback...")
if not run_pip_command(
[python_exe, "-m", "pip", "install", "opencv-python>=4.8.0"],
"OpenCV (regular version)"
):
failed_packages.append("opencv-python")
# Step 4: Install Pillow
if not run_pip_command(
[python_exe, "-m", "pip", "install", "Pillow>=10.0.0"],
"Pillow (image processing)"
):
failed_packages.append("Pillow")
# Step 5: Install PyQt5
if not run_pip_command(
[python_exe, "-m", "pip", "install", "PyQt5>=5.15.0"],
"PyQt5 (GUI framework)"
):
failed_packages.append("PyQt5")
# Step 6: scipy and scikit-image NOT USED - SKIPPED
print("\n⏭️ Skipping scipy and scikit-image (not required by application)")
# Step 7: Install PyTorch with CUDA
print("\n" + "="*60)
print("Installing PyTorch with CUDA support...")
print("This is a large download (2-3 GB) and may take several minutes")
print("="*60)
if not run_pip_command(
[python_exe, "-m", "pip", "install",
"torch>=2.0.0", "torchvision>=0.15.0",
"--index-url", "https://download.pytorch.org/whl/cu118"],
"PyTorch with CUDA 11.8"
):
# Try CPU version as fallback
print("\nCUDA version failed, trying CPU version...")
if not run_pip_command(
[python_exe, "-m", "pip", "install", "torch>=2.0.0", "torchvision>=0.15.0"],
"PyTorch (CPU version)"
):
failed_packages.append("torch")
# Step 8: Install EasyOCR (requires torch)
if not run_pip_command(
[python_exe, "-m", "pip", "install", "easyocr>=1.7.0"],
"EasyOCR (text recognition)"
):
failed_packages.append("easyocr")
# Step 9: Install web scraping tools
if not run_pip_command(
[python_exe, "-m", "pip", "install",
"requests>=2.31.0", "beautifulsoup4>=4.12.0", "lxml>=4.9.0"],
"Web Scraping Tools (requests, beautifulsoup4, lxml)"
):
failed_packages.append("web scraping tools")
# Step 10: Install PDF tools (PyMuPDF for embedded viewer, PyPDF2 for parsing)
if not run_pip_command(
[python_exe, "-m", "pip", "install", "PyMuPDF>=1.23.0", "PyPDF2>=3.0.0"],
"PDF Tools (PyMuPDF, PyPDF2)"
):
failed_packages.append("PDF tools")
# Step 11: YOLO/ultralytics NOT USED - SKIPPED
print("\n⏭️ Skipping ultralytics/YOLO (not required by application)")
# Step 12: Levenshtein/rapidfuzz NOT USED - SKIPPED
print("⏭️ Skipping Levenshtein/rapidfuzz (not required by application)")
# Summary
print("\n" + "="*60)
print("INSTALLATION SUMMARY")
print("="*60)
if not failed_packages:
print("\n[SUCCESS] ALL DEPENDENCIES INSTALLED SUCCESSFULLY!")
print("\nIC Authenticator is ready to use.")
return True
else:
print("\n[WARNING] INSTALLATION COMPLETED WITH WARNINGS")
print("\nThe following packages failed to install:")
for pkg in failed_packages:
print(f" [X] {pkg}")
print("\nThe application may not work correctly.")
print("Please check your internet connection and try running the installer again.")
return False
if __name__ == "__main__":
try:
success = main()
print("\n" + "="*60)
if success:
print("successfully installed all dependencies.")
# print("\nWindow will close automatically in 1 second...")
# time.sleep(1)
else:
print("\nWindow will close automatically in 2 seconds...")
time.sleep(2)
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\n\n[CANCELLED] Installation cancelled by user")
time.sleep(1)
sys.exit(1)
except Exception as e:
print(f"\n\n[FATAL ERROR] {str(e)}")
print("\nPlease report this error to the developer.")
print("\nWindow will close automatically in 2 seconds...")
time.sleep(2)
sys.exit(1)