Opencv is a library that is very helpful in image pre or post-processing. If you are a python programmer and you are unable to install OpenCV, then this post is for you. importerror no module named cv2 error occurs when cv2 module is not properly installed or its path is not properly set or configured. The straight way fix for this error (no module named cv2) is to reinstall this module (OpenCV-python).
In some scenario reinstalling this module automatically remove the older version. But in some scenarios, We need to manually delete the older or incompatible version of cv2 module (OpenCV-python). In this article, We will encounter these ways one by one.
Importerror no module named cv2 –
There are so many ways to install this packager. Let’s see one by one.
Method 1: Using pip package Manager-
1.1 Use the below command to fix this issue.
pip install opencv-python
1.2 In the case of the Python 3. x version, You may use the below command.
pip3 install opencv-python
If the above command is not working. There may be a strong possibility that the pip package manager is not updated. So install it.
python -m pip install --upgrade pip
Method 2: Using conda package Manager-
In the above section, we have used the pip package manager. The conda manager is the same as pip. So we can also use conda to install the OpenCV or cv2 module. Here is the way to do so.
conda install opencv
Well, At the beginning of the article, I have mentioned that reinstall any module will first uninstall the older version. But you manually do it with the below command also.
pip uninstall opencv-python
It will manually uninstall the module.
“importerror no module named cv2” is a very common error. Also, the import errors whether for cv2 or any other module has the same solution. Sometimes you get this error when you wrongly type the import statement. For example, instead of writing import cv2 , you write import cv . This leads to an import error when you run the code. I hope once you read this article, You may easily fix this error. Still, If you think, You are stuck. Please contact us or comment below on the comment box. We will surely assist in this.
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.