[Python] `ModuleNotFoundError: No module named 'cv2'` even after installing `opencv-python`

Discussão em 'Python' iniciado por Stack, Janeiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use OpenCV in Python 3.12.2 on Windows, but I keep encountering the error:

    ModuleNotFoundError: No module named 'cv2'


    Here’s what I’ve done so far:


    1. Installed OpenCV:

      pip install opencv-python


      Output of pip show opencv-python:

      Name: opencv-python
      Version: 4.10.0.84
      Location: C:\Users\lautr\AppData\Local\Programs\Python\Python312\Lib\site-packages
      Requires: numpy

    2. Verified Python and Pip Versions:

      python --version
      Python 3.12.2

      pip --version
      pip 24.3.1 from C:\Users\lautr\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip (python 3.12)

    3. Tested Import in Python Shell: When I run:

      import cv2
      print(cv2.__version__)


      I get the error:

      ModuleNotFoundError: No module named 'cv2'

    4. Uninstalled and Reinstalled OpenCV: I ran:

      pip uninstall opencv-python opencv-contrib-python opencv-python-headless opencv-contrib-python-headless
      pip install opencv-python


      But the issue persists.


    5. Checked for Multiple Python Installations: Output of where python and where pip:

      C:\Users\lautr\AppData\Local\Programs\Python\Python312\python.exe
      C:\Users\lautr\AppData\Local\Programs\Python\Python312\Scripts\pip.exe

    6. Ensured Dependencies Are Installed:
      • numpy is installed: pip install numpy
      • Visual C++ Redistributable 2015-2022 is installed.

    7. Other Information:
      • My system: Windows 10
      • OpenCV version: 4.10.0.84
      • Python version: 3.12.2
      • Pip version: 24.3.1

    Despite all these steps, I am unable to resolve the issue. Is there something I’m missing? Could this be related to Python 3.12 compatibility?

    Any help would be greatly appreciated!

    Continue reading...

Compartilhe esta Página