Why is Pylint telling me 'module cv2 has no member'?
Solution 1
If you don't want to add more config, please add this code to your config file, instead of 'whitelist'.
{
"python.linting.pylintArgs": ["--generate-members"],
}
relevent question: how-do-i-get-pylint-to-recognize-numpy-member
Solution 2
I had the same problem. My setup is Python 3.6.6 64 bit AMD My IDE is Visual Studio Code 1.46.1
My research led me to https://answers.opencv.org/question/200869/e1101module-cv2-has-no-imread-member/. One of the comments on the page linked above says to replace your import statement with one of this format:
from cv2 import cv2
Save your changes and allow your linter to reload. Viola! The error disappears.
Please mark as answer if this helps (I know it's been a while this question was asked).
Cheers.
Admin
Updated on June 05, 2022Comments
-
Admin about 2 years
I keep getting pylint errors saying:
module 'cv2' has no "something" member
and my cv2 module doesn't work.
I'm clueless as to why; as far as I know I installed it correctly. I even uninstalled and reinstalled about 20 times.
When i print out the modules i have in my python lib cv2 is printed; its functions are printed correctly. I'm using python 3.6.6 and don't have another version of python installed.
For example, this code will print: "the images are the same" no matter what images I'm giving it, as the 2 images will always be equal to "None".
import cv2 import numpy as np image1 = cv2.imread("1.jpg") image2 = cv2.imread("2.jpg") difference = cv2.subtract(image1, image2) result = not np.any(difference) #if difference is all zeros it will return False if result is True: print ("The images are the same") else: cv2.imwrite("result.jpg", difference) print ("the images are different")
Anyone know whats going on?
-
krflol over 5 yearscv2\cv2 doesn't exist. cv2\data does, hence why the linting should reveal cv2.haarcascades, as it is in the data_init_.py
-
Admin over 5 yearsso should i move the init.py? if so where?
-
Admin over 5 yearsi have 2 init.py for some reason one in Python\Python36\Lib\site-packages\cv2 and one in Python\Python36\Lib\site-packages\cv2\data
-
krflol over 5 yearsLet me clarify, your code works when it runs but the linting doesn't?
-
Admin over 5 yearslinting gives an error even tho the module exist as it is in the lib folder, even more advanced tools to print out my python modules did print out the cv2 module and even printing the modules functions was successful and correct, but the module itself doesnt work properly as using the modules functions simply doesnt work as it should
-
krflol over 5 years"Doesn't work as it should" at runtime? Are you getting an actual exception when you run the script?
-
Admin over 5 yearsprint(image1)=None same for image2 and diffrence result in undefined error only if i print it tho, so running the code as is will just print "images are the same"
-
krflol over 5 yearsThats a different question, but probably a much better image comparison tutorial can be found here.pyimagesearch.com/2017/06/19/…
-
Admin over 5 yearsas i already stated, this code is copy pasted from an image comparison tutorial, its all purpose is to add some information on the problem, plz stick to the problem stated in the question, thank u. btw atm the 2 images are equal to "None" as "imread" isnt recognized
-
Dave W. Smith over 5 yearsIf
imread
isn't recognized, that code will explode, not returnNone
. Ifcv.imread()
is returningNone
, then check your filenames/paths. And your questions reads as if you're asking about two problems. -
Admin over 5 yearsWhat ways are u suggesting for doing so? i tried a few and they all came correct
-
Dave W. Smith over 5 yearsI suggest checking the im1 and im2 aren't
None
, and reporting those as "file not found". If both fail to read,cv2.subtract(None, None)
will give youNone
, andnp.any(None)
likewise returnsNone
.not None
isTrue
, causing that code to always report "Images are the same" if both images fail to read. -
ScipioAfricanus almost 5 yearsis there something I can do in pylintrc to add this?
-
serwus almost 4 yearsBoth
import cv2
andfrom cv2 import cv2
worked, but only the latter prevented my IDE from underlining everycv2
in the code. -
duff18 over 3 yearsas stated by A. J. Paul in an answer below you need to set
generated-members=cv2
in your.pylintrc
file -
bers over 2 yearsThis answer is not only wrong, it breaks
pylint
.