-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_python312.py
More file actions
246 lines (207 loc) · 7.28 KB
/
fix_python312.py
File metadata and controls
246 lines (207 loc) · 7.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/env python3
"""
Python 3.12 Compatible Installation Script
Fixes the pkgutil.ImpImporter error and installs all dependencies
"""
import subprocess
import sys
import os
import platform
def upgrade_pip():
"""Upgrade pip to latest version"""
print("🔄 Upgrading pip...")
try:
subprocess.run([
sys.executable, "-m", "pip", "install", "--upgrade", "pip"
], check=True)
print("✅ pip upgraded successfully")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Failed to upgrade pip: {e}")
return False
def install_setuptools_wheel():
"""Install setuptools and wheel first"""
print("📦 Installing setuptools and wheel...")
try:
subprocess.run([
sys.executable, "-m", "pip", "install", "--upgrade",
"setuptools==69.0.0", "wheel==0.42.0"
], check=True)
print("✅ setuptools and wheel installed")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Failed to install setuptools/wheel: {e}")
return False
def install_core_packages():
"""Install core packages one by one"""
print("📦 Installing core packages...")
core_packages = [
"numpy==1.24.3",
"Pillow==10.1.0",
"requests==2.31.0",
"python-dotenv==1.0.0",
"pydantic-settings==2.0.3"
]
for package in core_packages:
try:
print(f" Installing {package}...")
subprocess.run([
sys.executable, "-m", "pip", "install", package
], check=True)
print(f" ✅ {package}")
except subprocess.CalledProcessError as e:
print(f" ❌ {package}: {e}")
def install_ml_packages():
"""Install ML packages"""
print("🤖 Installing ML packages...")
ml_packages = [
"torch==2.1.0",
"transformers==4.35.0",
"sentencepiece==0.1.99"
]
for package in ml_packages:
try:
print(f" Installing {package}...")
subprocess.run([
sys.executable, "-m", "pip", "install", package
], check=True)
print(f" ✅ {package}")
except subprocess.CalledProcessError as e:
print(f" ❌ {package}: {e}")
def install_web_packages():
"""Install web framework packages"""
print("🌐 Installing web packages...")
web_packages = [
"fastapi==0.115.8",
"uvicorn[standard]==0.24.0",
"python-multipart==0.0.6",
"PyJWT==2.9.0"
]
for package in web_packages:
try:
print(f" Installing {package}...")
subprocess.run([
sys.executable, "-m", "pip", "install", package
], check=True)
print(f" ✅ {package}")
except subprocess.CalledProcessError as e:
print(f" ❌ {package}: {e}")
def install_ai_packages():
"""Install AI packages"""
print("🧠 Installing AI packages...")
ai_packages = [
"google-generativeai==0.8.3",
"gtts==2.4.0",
"nltk==3.8.1"
]
for package in ai_packages:
try:
print(f" Installing {package}...")
subprocess.run([
sys.executable, "-m", "pip", "install", package
], check=True)
print(f" ✅ {package}")
except subprocess.CalledProcessError as e:
print(f" ❌ {package}: {e}")
def install_optional_packages():
"""Install optional packages (may fail but continue)"""
print("🔧 Installing optional packages...")
optional_packages = [
"pytesseract==0.3.10",
"opencv-python==4.8.1.78",
"langchain-groq==0.0.1",
"langchain==0.1.0",
"langchain-community==0.0.10"
]
for package in optional_packages:
try:
print(f" Installing {package}...")
subprocess.run([
sys.executable, "-m", "pip", "install", package
], check=True)
print(f" ✅ {package}")
except subprocess.CalledProcessError as e:
print(f" ⚠️ {package}: {e} (continuing...)")
def test_imports():
"""Test if critical imports work"""
print("\n🧪 Testing critical imports...")
critical_imports = [
"fastapi",
"uvicorn",
"numpy",
"PIL",
"requests"
]
success_count = 0
for module in critical_imports:
try:
__import__(module)
print(f"✅ {module}")
success_count += 1
except ImportError as e:
print(f"❌ {module}: {e}")
print(f"\n📊 Critical imports: {success_count}/{len(critical_imports)} successful")
return success_count >= 3 # At least 3 out of 5 should work
def test_fastapi():
"""Test FastAPI startup"""
print("\n🚀 Testing FastAPI startup...")
try:
# Change to FastAPI directory
original_dir = os.getcwd()
os.chdir("MySarkar/fastAPI")
# Add current directory to path
sys.path.insert(0, ".")
# Try to import the main app
from app.main import app
print("✅ FastAPI app imported successfully!")
# Change back
os.chdir(original_dir)
return True
except Exception as e:
print(f"❌ FastAPI startup failed: {e}")
os.chdir(original_dir)
return False
def main():
print("🔧 Python 3.12 Compatible Installation")
print("="*50)
print(f"🐍 Python Version: {sys.version}")
print(f"💻 Platform: {platform.system()} {platform.release()}")
# Check if we're in the right directory
if not os.path.exists("MySarkar/fastAPI"):
print("❌ MySarkar/fastAPI directory not found!")
print("Please run this script from the project root directory")
return
# Step 1: Upgrade pip
if not upgrade_pip():
print("⚠️ Pip upgrade failed, continuing...")
# Step 2: Install setuptools and wheel
if not install_setuptools_wheel():
print("⚠️ Setuptools/wheel installation failed, continuing...")
# Step 3: Install packages in order
install_core_packages()
install_web_packages()
install_ml_packages()
install_ai_packages()
install_optional_packages()
# Step 4: Test imports
if test_imports():
print("\n✅ Core functionality is working!")
else:
print("\n⚠️ Some imports failed, but continuing...")
# Step 5: Test FastAPI
if test_fastapi():
print("\n🎉 FastAPI is working!")
print("\n📱 You can now start FastAPI with:")
print(" cd MySarkar/fastAPI")
print(" python -m uvicorn app.main:app --reload")
else:
print("\n⚠️ FastAPI has issues, but core packages are installed")
print("📝 You may need to check the specific error messages")
print("\n" + "="*50)
print("🏛️ Installation completed!")
print("📋 Next steps:")
print("1. Try starting FastAPI: cd MySarkar/fastAPI && python -m uvicorn app.main:app --reload")
print("2. If OCR doesn't work, install Tesseract OCR manually")
print("3. Run the complete system: python start_complete_system.py")
if __name__ == "__main__":
main()