'Can't import CV2 on Virtual Environment on Windows 10

I'm having a problem with importing cv2 on a virtual environment (windows 10). However, when I use Python interpreter and write import cv2, I can import it. It's when I try to run the script from the command prompt, I get an error

ModuleNotFoundError: No module named 'cv2' 

I've tried some solutions on the previous Stack overflow posts but none of them worked for me. I tried with both Python 3.7 and Python 3.8 with a separate virtual environment.

I checked that cv2 folder is in the site-packages folder.

The solutions I've tried are:

  1. Change the name of cv2.py to cv.py inside the cv2 folder.
  2. Install cv2 through pip install opencv-contrib-python then pip install opencv-python
  3. Install opencv_python‑4.5.5‑cp38‑cp38‑win_amd64.whl

Any suggestion?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source