Skip to content

fix: say why an OpenCV contrib module is missing - #182

Merged
petercorke merged 3 commits into
mainfrom
feat/cv2-contrib-shim
Nov 20, 2026
Merged

petercorke merged 3 commits into
mainfrom
feat/cv2-contrib-shim

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Pyodide, and so JupyterLite, ships plain OpenCV without the contrib modules (ximgproc, xfeatures2d and others), so using one failed with a bare AttributeError: module 'cv2' has no attribute 'ximgproc'. On import, MVTB now puts a stand-in for each missing contrib module into cv2. Using it raises an AttributeError subclass that says the contrib modules are not installed, how to install them on a desktop (pip install opencv-contrib-python), and that this is not possible in JupyterLite. Because it is an AttributeError, existing hasattr() checks still work, and a module that is present is left alone. The module list is OpenCV's, not MVTB's, so call sites don't change. A normal pip install of MVTB already brings in contrib, so this only appears in JupyterLite or after --no-deps. Tests included.

🤖 Generated with Claude Code

petercorke and others added 2 commits November 20, 2026 11:17
Pyodide, and so JupyterLite, has plain OpenCV without ximgproc, xfeatures2d and the
other contrib modules, so using one failed with a bare AttributeError.  A stand-in for
each missing module now raises an AttributeError that names the module and says it needs
opencv-contrib-python.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 17 complexity · 0 duplication

Metric Results
Complexity 17
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit e7c2ae5 into main Nov 20, 2026
33 checks passed
@petercorke
petercorke deleted the feat/cv2-contrib-shim branch November 20, 2026 01:46
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant