pasha
pasha

Reputation: 416

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)

Upvotes: 21

Views: 39217

Answers (7)

WinterGrim
WinterGrim

Reputation: 68

Hello i allow myself to give an answer to this question because i had the same problem and only the following method worked for me:

  1. Go to pylint extension sittings and find the Pylint args in vscode
  2. clic on the blue button and ad cv2 in the space

In fact it's the same thig that adding:

    "pylint.args": [
    "cv2"
    ]

in the settings.json between the {} (don't forget to ad a comma after the previous element)

Upvotes: 0

Amila Viraj
Amila Viraj

Reputation: 1064

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

Upvotes: 57

Adrian
Adrian

Reputation: 620

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/

Upvotes: 10

Vaibhav Khandelwal
Vaibhav Khandelwal

Reputation: 153

try by putting:

**from cv2 import cv2**

this will surely work

Upvotes: -5

igosulim
igosulim

Reputation: 31

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

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

Works for me.

Upvotes: 3

Neville Lusimba
Neville Lusimba

Reputation: 887

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

Upvotes: 47

Niroop_satish
Niroop_satish

Reputation: 24

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

it has worked for me.

Upvotes: -1

Related Questions