close

[Solved] ImportError: No module named cv2

I am trying to use CV2 but I am facing the following error: ImportError: No module named cv2 In this Exerror article, We are going to learn about How to reproduce this error and we will discuss All Possible Solutions Let’s Get Start With This Article.

How ImportError: No module named cv2 Error Occurs?

I am trying to use CV2 but I am facing the following error.

ImportError: No module named cv2

So here I am writing all the possible solutions that I have tried to resolve this error.

How To Solve ImportError: No module named cv2 Error?

  1. How To Solve ImportError: No module named cv2 Error?

    To Solve ImportError: No module named cv2 Error First of all, check that you have opencv-python installed in your system or Not By running this command in your terminal: pip3 show opencv-python If you already have opencv-python installed in your system then install opencv-contrib-python by running this command: pip install opencv-contrib-python And now, Your error will be solved. Thanks.

  2. ImportError: No module named cv2

    ImportError: No module named cv2 Usually Occurs when we forgot to install OpenCV-python Or we are using an incorrect environment To Solve ImportError: No module named cv2 Error Just Install OpenCV-python by running pip install opencv-python command and Your error will be solved: If You are using Python 2 Then run This command: pip install opencv-python If You are using Python 3 then run this command: pip3 install opencv-python If You don't have the pip Path Variable set then run this command: python3 -m pip install opencv-python Now, Your error will be solved. Thank you.

Solution 1: Install OpenCV-python

ImportError: No module named cv2 Usually Occurs when we forgot to install OpenCV-python Or we are using an incorrect environment To Solve ImportError: No module named cv2 Error Just Install OpenCV-python by running pip install opencv-python command and Your error will be solved.

If You are using Python 2 Then run This command.

pip install opencv-python

And If You are using Python 3 then run this command.

pip3 install opencv-python

If You don’t have the pip Path Variable set then run this command.

# For Python2
python -m pip install opencv-python

# For Python3
python3 -m pip install opencv-python

Now, Your error will be solved. Thank you.

Solution 2: Install opencv-contrib-python

First of all, check that you have opencv-python installed in your system or Not By running this command in your terminal.

pip3 show opencv-python

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

pip install opencv-contrib-python

And now, Your error will be solved. Thanks.

Solution 3: For virtual environment

If You are using a Virtual Environment then Follow these steps. First of all create virtual env by running this command.

python3 -m venv venv

Then activate it by running,

# For linux macos
source venv/bin/activate

#For Windows
venv\Scripts\activate.bat

Then install opencv-python in your virtual environment.

pip install opencv-python

I Hope, Your error may be solved now.

Conclusion

It’s all About this error. I hope We Have solved Your error. Comment below Your thoughts and your queries. Also, Comment below on which solution worked for you.

Also, Read

Leave a Comment