From ab1b9918cb7e86139e0adc3f76915a7e318558ce Mon Sep 17 00:00:00 2001 From: Robert Love Date: Fri, 12 Jun 2026 18:55:04 -0400 Subject: [PATCH] fix(cv): fully purge base OpenCV before reinstalling opencv-python MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first attempt (uninstall + force-reinstall) failed the build-time assert on arm64: the nvcr `opencv` and the `opencv-python` wheel share the same site-packages cv2/ directory, so a plain uninstall left residual files that kept shadowing the wheel — `import cv2` still resolved to the headless build (FFMPEG: NO). Confirmed on the real arm64 node: a clean opencv-python 4.13 install reports FFMPEG: YES (the aarch64 wheel does ship FFmpeg), and site-packages held both opencv-4.10.0.dist-info and opencv_python-4.11.0.86.dist-info pointing at one cv2/ dir. Fix: uninstall every opencv variant, then rm -rf the leftover cv2/ dir, opencv*.dist-info, and opencv_python.libs before a clean opencv-python install. Works on amd64 and arm64; the FFmpeg assert still guards regressions. Co-Authored-By: Claude Opus 4.8 --- cv/Dockerfile.base | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cv/Dockerfile.base b/cv/Dockerfile.base index c01cf08..bed9d95 100644 --- a/cv/Dockerfile.base +++ b/cv/Dockerfile.base @@ -63,14 +63,20 @@ RUN --mount=type=cache,target=/root/.cache/pip \ && rm /tmp/req.txt # The nvcr.io base ships its own OpenCV (pip package name `opencv`, built -# WITHOUT FFmpeg) which shadows the opencv-python wheel from req.txt — the -# imported cv2 ends up FFMPEG: NO, so cv2.VideoCapture can't open RTSP and -# every camera open fails instantly. Drop the base build and force-reinstall -# the pip wheel (FFMPEG: YES), then assert the backend is present so this -# regression cannot return silently in a future base bump. +# WITHOUT FFmpeg) that installs into the SAME site-packages `cv2/` directory +# as the opencv-python wheel from req.txt and shadows it — `import cv2` loads +# the headless build (FFMPEG: NO), so cv2.VideoCapture can't open RTSP and +# every camera open fails instantly. A plain `pip uninstall` + reinstall is +# not enough: the two packages share the cv2/ dir, so residual files keep +# shadowing the wheel. Purge every opencv variant AND the leftover cv2/ dir, +# then install the opencv-python wheel clean (FFmpeg-enabled on both amd64 and +# arm64), and assert the backend is present so a future base bump can't +# silently reintroduce the regression. RUN --mount=type=cache,target=/root/.cache/pip \ - pip uninstall -y opencv opencv-python opencv-python-headless || true \ - && pip install --force-reinstall --no-deps "opencv-python>=4.10" \ + pip uninstall -y opencv opencv-python opencv-python-headless opencv-contrib-python || true \ + && SITE="$(python3 -c 'import site; print(site.getsitepackages()[0])')" \ + && rm -rf "$SITE/cv2" "$SITE"/opencv*.dist-info "$SITE"/opencv_python.libs \ + && pip install --no-cache-dir "opencv-python>=4.10" \ && python3 -c "import cv2; bi=cv2.getBuildInformation(); assert any('FFMPEG' in l and l.strip().endswith('YES') for l in bi.splitlines()), 'OpenCV FFMPEG backend missing — RTSP capture would fail'; print('cv2', cv2.__version__, 'FFMPEG: YES')" # Diagnostic: print the compiled arch list so a future regression is