[Python] Module 'cv2' has no '__version__' member

Discussão em 'Python' iniciado por Stack, Maio 10, 2025.

  1. Stack

    Stack Membro Participativo

    am trying to print the versions of various installed packages in my Python script. Here is the code I am using:

    ## ---------------------------------------------
    ## Installed package version information
    ## ---------------------------------------------
    ## Importing modules
    import torch
    import torchvision
    import numpy as np
    import cv2

    ## Printing version information for each package
    print(f'torch v.{torch.__version__}')
    print(f'torchvision v.{torchvision.__version__}')
    print(f'numpy v.{np.__version__}')
    print(f'cv2 v.{cv2.__version__}')


    When I run this script, it works perfectly, and the version of OpenCV (cv2) is printed correctly. However, in my IDE (Visual Studio Code), I get the following warning:

    Module 'cv2' has no '__version__' member


    My Environment: Python version: 3.9 OpenCV version: 2.4.1 PyTorch and torchvision installed via Conda OpenCV installed via Conda IDE: Visual Studio Code OS: Windows 10 My Question: Why does this warning appear in my IDE, and how can I fix or suppress it? Is this an issue with OpenCV, my IDE, or a type-checking tool like mypy?

    Continue reading...

Compartilhe esta Página