pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.29k stars 1.13k forks source link

cv2 module members are not recognized #2426

Closed uriva closed 6 years ago

uriva commented 6 years ago

When importing cv2 I get errors such as:

[pylint] E1101:Module 'cv2' has no 'imread' member [pylint] E1101:Module 'cv2' has no 'resize' member [pylint] E1101:Module 'cv2' has no 'imshow' member [pylint] E1101:Module 'cv2' has no 'waitKey' member [pylint] E1101:Module 'cv2' has no 'destroyAllWindows' member

etc'

(the code itself runs fine)

I'm using VSCode 1.26.1 and Python 3.6.5.

See this issue for more complaints: https://github.com/DonJayamanne/pythonVSCode/issues/623

domajstorovic commented 2 years ago

I can't believe how many people here are recommending to edit the clumsy vscode setting "python.linting.pylintArgs".

Not only is it just solving the issue locally, especially when you edit your global vscode settings.json, it also overrides any settings from a .pylintrc file, which is not immediately obvious. Using vscode's settings to add command line arguments to some binary running in the background is a bad idea in general, and should only be done as a last resort.

What you should really do, in my opinion, is to generate a pylint configuration file inside your project folder like this:

pylint --generate-rcfile > .pylintrc

and then edit the settings extension-pkg-allow-list and generated-members there.

You can of course also edit these settings in your user- or system-wide .pylintrc, I'd advise against that though.

This. By far the most elegant solution. Thanks!

KukavicaHome commented 2 years ago

VS2019 works for me.

qngv98 commented 2 years ago

install opencv_headless and it works for me.

ZhiliangWu commented 1 year ago

For pyproject.toml file, add the following

[tool.pylint.typecheck]
generated-members = "cv2.*"
Pierre-Sassoulas commented 1 year ago

Note that using genrated-members should be the last solution if nothing else work, because it will disable pylint's check on everything coming from cv2.

knowledgeLover commented 1 year ago

pip installation is wrong.

Easiest solution and you do not need to worry about any settings or incorrect changes. Much safer.

pip install opencv-python-headless

Try installing opencv-python-headless python dependency instead of opencv-python. That includes a precompiled binary wheel with no external dependencies (other than numpy), and is intended for headless environments like Docker. This saved almost 700mb in my docker image compared with using the python3-opencv Debian package (with all its dependencies).

The package documentation discusses this and the related (more expansive) opencv-contrib-python-headless pypi package.

DungGramer commented 10 months ago

Update 2023:

  "pylint.args": ["--extension-pkg-whitelist=cv2"]
LambdaScorpii commented 3 months ago

Hello There,

since the new release of OpenCV this no longer works. It still throws the no member error, regardless if you put in "--extension-pkg-whitelist=cv2" or --extension-pkg-allow-list=cv2 (as suggested in the official documentation, as "whitelist"seems dprecated). Any suggestion how to make that work?

Generating all members defies the purpose of PyLint in my opinion...

Pierre-Sassoulas commented 3 months ago

Could you open a new issue with a reproducer please @LambdaScorpii ? (Edit: Sorry Bad ping my Bad)