Lemontropia-Suite/verify_vision.py

124 lines
3.8 KiB
Python

"""
Verify and fix Computer Vision dependencies for Python 3.13
"""
import subprocess
import sys
def check_torch():
"""Check PyTorch installation."""
try:
import torch
print(f"✅ PyTorch {torch.__version__} installed")
print(f" CUDA available: {torch.cuda.is_available()}")
return True
except Exception as e:
print(f"❌ PyTorch error: {e}")
return False
def check_paddle():
"""Check PaddlePaddle installation."""
try:
import paddle
print(f"✅ PaddlePaddle {paddle.__version__} installed")
return True
except Exception as e:
print(f"❌ PaddlePaddle error: {e}")
return False
def check_paddleocr():
"""Check PaddleOCR installation."""
try:
from paddleocr import PaddleOCR
print(f"✅ PaddleOCR installed")
return True
except Exception as e:
print(f"❌ PaddleOCR error: {e}")
return False
def check_opencv():
"""Check OpenCV installation."""
try:
import cv2
print(f"✅ OpenCV {cv2.__version__} installed")
return True
except Exception as e:
print(f"❌ OpenCV error: {e}")
return False
def install_fix():
"""Install working versions for Python 3.13."""
print("\n🔧 Installing packages for Python 3.13...")
# Install latest PyTorch (Python 3.13 compatible)
print("\n[1/3] Installing PyTorch (latest)...")
subprocess.check_call([
sys.executable, "-m", "pip", "install",
"torch", "torchvision",
"--index-url", "https://download.pytorch.org/whl/cpu"
])
# Install PaddlePaddle (latest for Python 3.13)
print("\n[2/3] Installing PaddlePaddle...")
subprocess.check_call([
sys.executable, "-m", "pip", "install",
"paddlepaddle"
])
# Install PaddleOCR WITHOUT PyMuPDF (it fails to build)
print("\n[3/3] Installing PaddleOCR (without PyMuPDF)...")
subprocess.check_call([
sys.executable, "-m", "pip", "install",
"paddleocr", "--no-deps" # Install without dependencies first
])
# Then install PaddleOCR dependencies except PyMuPDF
print("\n[4/4] Installing PaddleOCR dependencies...")
deps = [
"shapely", "scikit-image", "imgaug", "pyclipper",
"lxml", "tqdm", "numpy", "visualdl", "rapidfuzz",
"opencv-python", "opencv-contrib-python",
"cython", "Pillow", "pyyaml", "pdf2docx",
"premailer", "attrdict", "openpyxl", "fire", "fonttools"
]
subprocess.check_call([
sys.executable, "-m", "pip", "install"
] + deps)
print("\n✅ Installation complete!")
if __name__ == "__main__":
print("=" * 50)
print("Computer Vision Dependency Check")
print("=" * 50)
print()
all_ok = True
all_ok &= check_torch()
all_ok &= check_paddle()
all_ok &= check_paddleocr()
all_ok &= check_opencv()
print()
print("=" * 50)
if all_ok:
print("✅ All dependencies OK! Computer Vision should work.")
else:
print("❌ Some dependencies missing or broken.")
response = input("\nWould you like to auto-fix? (y/n): ")
if response.lower() == 'y':
try:
install_fix()
print("\n✅ Installation complete! Please restart the app.")
except Exception as e:
print(f"\n❌ Installation failed: {e}")
print("\nTry manual installation:")
print("1. pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu")
print("2. pip install paddlepaddle")
print("3. pip install paddleocr --no-deps")
print("4. pip install shapely scikit-image opencv-python")
else:
print("\nSkipping installation.")
print()
input("Press Enter to exit...")