0

I tried a course on Face Detection using OpenCV and I got stuck on the first step itself because after running the test code, PyCharm shows ModuleNotFoundError: No module named 'cv2'. However I have installed OpenCV successfully using pip install opencv-contrib-python and my pip has been updated to the latest version. I'm using Windows 10 (64 bits) Python Version: 3.9.6 Numpy Version: 1.21.1 OpenCV Version: 4.5.3.56 Pip Version: 21.2.2 Code to print the 3D Matrix of a colored image:

import cv2
img = cv2.imread("C:\\Users\\bibhr\\PycharmProjects\\pythonProject2\\lfc.jpg",1)
print(img)

Error Message:

ModuleNotFoundError: No module named 'cv2'

Image for pip list: enter image description here

I have tried uninstalling and reinstalling Python and OpenCV but none of that worked Any help would be appreciated as I need to finish this project in a couple of weeks.

Also, I couldn't find cv2.so file in C:\Users\bibhr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\cv2

Is that the reason? If yes, then how do I find cv2.so in my computer? (The search box couldn't find it either)

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

2 Answers2

0

Try to use pip install opencv-python instead of opencv-contrib-python Hope this will be helpful!

Khoi Le
  • 15
  • 6
  • I did use ```pip install opencv-python``` in the beginning, but still it showed similar error. So I used ```pip install opencv-contrib-python``` the second time. – rikudousennin Jul 31 '21 at 09:20
  • Have you installed `numpy`? https://docs.opencv.org/4.5.2/d5/de5/tutorial_py_setup_in_windows.html and install Visual C++ Redistributable 2015 (https://pypi.org/project/opencv-contrib-python/) – Khoi Le Jul 31 '21 at 09:29
0

Thanks for the help everyone. I solved the issue by changing the Project interpreter from Virtual Environment to Existing Interpreter.