fix(pdf): make pdfplumber/pymupdf imports resilient with graceful fallback and add auto-venv discovery in app.py

This commit is contained in:
Abhinav Gupta
2026-10-03 10:37:22 +05:30
parent c6bfcdc17d
commit ae5c96895d
2 changed files with 90 additions and 31 deletions
+16 -1
View File
@@ -4,9 +4,24 @@ import sys
from pathlib import Path
# Ensure src/ is on Python search path
src_dir = Path(__file__).parent / "src"
root_dir = Path(__file__).resolve().parent
src_dir = root_dir / "src"
if str(src_dir) not in sys.path:
sys.path.insert(0, str(src_dir))
# Automatically detect and include local virtual environment site-packages
for venv_name in ("env", ".venv", "venv"):
# Windows
win_sp = root_dir / venv_name / "Lib" / "site-packages"
if win_sp.exists() and str(win_sp) not in sys.path:
sys.path.insert(0, str(win_sp))
# Linux / macOS
linux_lib = root_dir / venv_name / "lib"
if linux_lib.exists():
for py_dir in linux_lib.glob("python*"):
sp = py_dir / "site-packages"
if sp.exists() and str(sp) not in sys.path:
sys.path.insert(0, str(sp))
# Import and execute main Streamlit UI
from medical_coding.ui.app import * # noqa: E402, F401, F403