'cv2 python has no imread member

I pip installed OpenCV-python. The installation seems to be fine and I tested it out on the python IDLE. It ran without any problems. I've been trying to run it on VS Code but it doesn't seem to work. The autocomplete recognizes the imread function but when I type it in it throws up an error saying cv2 has no imread member. I am using the most updated version of python

I am calling it like this:img2 = cv2.imread("C:\Biometric\min.jpg", 0)



Solution 1:[1]

Since you are trying to executing this with VS Code, try following steps

  1. Open palette on VS Code (use specifies command): CTRL + Shift + P
  2. Then select "Preferences > Open Settings (JSON)" option in the palette dropdown
  3. Then add the following line in the opened settings.json file python.linting.pylintArgs": ["--generate-members"]

this must work

Solution 2:[2]

I tried so many hacks. They were not working. Someone suggested:

from cv2 import cv2

I think this is the best solution to this problem

Solution 3:[3]

Solution 1: Change pylint settings

  1. Open the Command Palette from menu "View" or by pressing Ctrl + Shift + P
  2. Type "Preferences: Open Settings (JSON)" and hit enter to open the settings.json file
  3. In the block surrounded by curly braces add a comma to the last line and then add the line
"python.linting.pylintArgs": ["--generate-members=cv2.*"]
  1. Save using the menu "File" or by pressing Ctrl + S
  2. Go back to your python file and convince yourself that "cv2" is no longer flagged by the linter but all other types of errors are still detected

Solution 2: Use a different linter

  1. Open the Command Palette from menu "View" or by pressing Ctrl + Shift + P
  2. Type "Python: Select Linter" and hit enter
  3. Select a different linter, e.g. flake8.
    For a comparison of different linters check out https://realpython.com/python-code-quality/

Solution 4:[4]

If you could run your code by selecting "Run Python File In Terminal", it is possibly a bug from an extension of VS Code. See the issue for details

I think you could disable/uninstall the extension from your machine or ignore it.

Solution 5:[5]

Ctrl + Shift + P -> Preferences: Open Settings (JSON)
Then add the following:

"python.linting.pylintArgs": ["--generate-members"]

Works for me.

Solution 6:[6]

Go to the terminal and type pylint --extension-pkg-whitelist=cv2

it has worked for me.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 gmuraleekrishna
Solution 2 Neville Lusimba
Solution 3 Charlene Barina
Solution 4 Howard GENG
Solution 5 igosulim
Solution 6 Niroop_satish