[Solved] ModuleNotFoundError: No module named ‘cv2’

While are you trying to import the ‘opencv-python‘ module without installing the package or If you install it in an incorrect environment. Then you will face ModuleNotFoundError: No module named ‘opencv-python’, this error.

In this article, we will discuss about this ModuleNotFoundError: No module named ‘cv2’ error in Python. And how to resolve the error all the possible solutions with examples.

How to ModuleNotFoundError: No module named ‘cv2’ Error Occurs?

The Python error “ModuleNotFoundError: No module named ‘cv2’” occurs for multiple reasons:

  1. When have you installed pip install opencv-python, there have not opencv-python package.
  2. You have installed the opencv-python package in a different Python version.
  3. If you are using the virtual environment and cv2.py module is not installed in your virtual environment.
  4. Declaring a variable name cv2.
ImportError: No module named cv2

How To Fix ModuleNotFoundError: No module named ‘cv2’ Error?

There are different ways to fix ModuleNotFoundError: No module named ‘cv2’ error. Let us take a look at every solution.

  • How To Fix ModuleNotFoundError: No module named ‘cv2’ Error?

For the solve ModuleNotFoundError: No module named ‘cv2’ Error First you have to install OpenCV-python. So, opening your terminal in your project’s root directory If you are using python2 then run this command: pip install opencv-python Or if you are using python3 then run this command: pip3 install opencv-python If you don’t have pip path Variable then run this command: python3 -m pip install opencv-python Now, your error will be solved.

  • ModuleNotFoundError: No module named ‘cv2’

For the solve ModuleNotFoundError: No module named ‘cv2’ error First of all, check the opencv-python is installed or not. If not then run this command: pip3 show opencv-python Or if you have installed it in your system then install opencv-contrib-python by running this command: pip install opencv-contrib-python. Now, your error will be gone.

Solution 1: Install OpenCV-python

First, you need to install OpenCV-python by running this command.

# 👇️ For Python 2
pip install opencv-python

Or

# 👇️ For Python 3
pip3 install opencv-python

If you don’t have pip path variable then run this command:

# 👇️ For Python2
python -m pip install opencv-python

# 👇️ For Python3
python3 -m pip install opencv-python

Now, I hope your error will be solved.

Solution 2: Install opencv-contrib-python

First of all, check whether you have opencv-python installed or not. if you have not installed then run this command:

pip3 show opencv-python

If you have already opencv-python installed then install opencv-contrib-python by running this command.

pip install opencv-contrib-python

I hope this way works to solve your error.

Conclusion

In this article, we have discussed what causes the error and we have discussed ways to fix the error.

we hope this article has been informative. Thank you for reading. Kindly comment and let us know if you found it helpful.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Categories