fix: start.sh 增加 cv2 空壳兜底——pip 24.0 解压 abi3 wheel 偶发丢根文件(cv2.abi3.so/__init__.py 缺失致 OCR 全挂),检测后 pip download + zipfile 手动解压(幂等)
This commit is contained in:
@@ -16,4 +16,34 @@ fi
|
||||
pip uninstall -y -q opencv-python 2>/dev/null || true
|
||||
pip install -q -i https://pypi.tuna.tsinghua.edu.cn/simple "opencv-python-headless>=4.8,<5" # 5.x wheel 无 cv2 模块,锁定 4.x
|
||||
|
||||
# pip 24.0 解压 abi3 wheel 偶发丢根文件(4.14.0.94 实测 site-packages/cv2 只剩子目录,
|
||||
# cv2.abi3.so / __init__.py 缺失 → import cv2 成空壳,OCR 全挂)→ 空壳检测 + wheel 手动解压兜底(幂等)
|
||||
python3 - <<'PY'
|
||||
import glob, os, shutil, site, subprocess, sys, zipfile
|
||||
|
||||
def cv2_ok():
|
||||
try:
|
||||
import cv2
|
||||
return hasattr(cv2, "__version__") and cv2.__file__ is not None
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
if cv2_ok():
|
||||
sys.exit(0)
|
||||
print("cv2 空壳,wheel 手动解压修复...")
|
||||
r = subprocess.run(["pip", "download", "--no-deps", "-q",
|
||||
"-i", "https://pypi.tuna.tsinghua.edu.cn/simple",
|
||||
"-d", "/tmp/ocv", "opencv-python-headless>=4.8,<5"], capture_output=True)
|
||||
if r.returncode != 0:
|
||||
sys.exit(1)
|
||||
w = sorted(glob.glob("/tmp/ocv/opencv_python_headless*.whl"))[-1]
|
||||
with zipfile.ZipFile(w) as z:
|
||||
z.extractall("/tmp/ocv")
|
||||
dst = os.path.join(site.getsitepackages()[0], "cv2")
|
||||
shutil.rmtree(dst, ignore_errors=True)
|
||||
shutil.copytree("/tmp/ocv/cv2", dst)
|
||||
import cv2
|
||||
print(f"cv2 {cv2.__version__} 手动解压修复完成")
|
||||
PY
|
||||
|
||||
exec python -u web_server.py
|
||||
|
||||
Reference in New Issue
Block a user