Solve the problem "No module named 'cv2' " in python

来源:互联网 发布:58同城网络兼职日结 编辑:程序博客网 时间:2024/06/05 19:31

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

  1. 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.
  1. If you have an existing opencv-python installation, run pip uninstall opencv-python
  2. Install this package:

pip install opencv-contrib-python

  1. Import the package:

import cv2

For more details, please refer to contrib-opencv-python
原创粉丝点击