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 scenario, 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 Please use the below command to fix this issue.
pip install opencv-python
1.2 In case of 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.
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 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. 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 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.