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
解决Python cv2导入错误
本文介绍了解决Python中导入cv2模块时出现错误的方法。推荐安装opencv-contrib-python模块来解决此问题,并提供了详细的安装步骤及注意事项。
2607

被折叠的 条评论
为什么被折叠?



