From f78955f119c6af5b24d15a5e5026d820f05e58bf Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Thu, 20 Aug 2026 08:51:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20start.sh=20=E5=A2=9E=E5=8A=A0=20cv2=20?= =?UTF-8?q?=E7=A9=BA=E5=A3=B3=E5=85=9C=E5=BA=95=E2=80=94=E2=80=94pip=2024.?= =?UTF-8?q?0=20=E8=A7=A3=E5=8E=8B=20abi3=20wheel=20=E5=81=B6=E5=8F=91?= =?UTF-8?q?=E4=B8=A2=E6=A0=B9=E6=96=87=E4=BB=B6=EF=BC=88cv2.abi3.so/=5F=5F?= =?UTF-8?q?init=5F=5F.py=20=E7=BC=BA=E5=A4=B1=E8=87=B4=20OCR=20=E5=85=A8?= =?UTF-8?q?=E6=8C=82=EF=BC=89=EF=BC=8C=E6=A3=80=E6=B5=8B=E5=90=8E=20pip=20?= =?UTF-8?q?download=20+=20zipfile=20=E6=89=8B=E5=8A=A8=E8=A7=A3=E5=8E=8B?= =?UTF-8?q?=EF=BC=88=E5=B9=82=E7=AD=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/start.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/scripts/start.sh b/scripts/start.sh index 0241e6c..f0cb45a 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -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