When I try to import 'cv2' in python, an error arise saying "No module named 'cv2'. I have encountered this problem several times and it's easy to solve it. You can install "opencv-contrib-python" module to solve it. Below are some official descriptions about this module.
Wrapper package for OpenCV python bindings.
Unofficial OpenCV packages for Python with contrib modules.
Note: the usage of opencv-contrib-python might be restricted in some countries since the contrib package contains somepatented algorithms/non-free modules.
If you are looking for a version without the contrib modules, please install opencv-python instead.
The packages contain pre-compiled OpenCV binary with Python bindings. This enables super fast (usually < 10 seconds) OpenCVinstallation for Python.
If you need only OpenCV Python bindings, no separate OpenCV installation is required.
IMPORTANT NOTE
MacOS and Linux wheels do not support video related functionality (not compiled with FFmpeg).
Installation and Usage
- If you have previous/other version of OpenCV installed (e.g. cv2 module in the root of Python’s site-packages), remove it before installation to avoid conflicts.
- To further avoid conflicts and to make development easier, Python’s virtual environments are highly recommended for development purposes.
- If you have an existing opencv-python installation, run pip uninstall opencv-python
- Install this package:
pip install opencv-contrib-python
- Import the package:
import cv2