Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cv2 module members are not recognized #2426

Closed
uriva opened this issue Aug 20, 2018 · 52 comments
Closed

cv2 module members are not recognized #2426

uriva opened this issue Aug 20, 2018 · 52 comments

Comments

@uriva
Copy link

@uriva uriva commented Aug 20, 2018

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

@PCManticore
Copy link
Member

@PCManticore PCManticore commented Aug 21, 2018

This should work if you pass --extension-pkg-whitelist=cv2 to pylint as in pylint --extension-pkg-whitelist=cv2 .... The reason for this is that cv2 seems to be an extension package, thus it's C code that pylint cannot understand. The extension whitelist flag lets pylint import cv2 in order to build an AST out of the imported cv2 module.

@uriva
Copy link
Author

@uriva uriva commented Aug 21, 2018

To future readers, in vsc this means adding this line to the settings:
"python.linting.pylintArgs": ["--extension-pkg-whitelist=cv2"]

@cipri-tom
Copy link

@cipri-tom cipri-tom commented Sep 12, 2018

Thanks @PCManticore

However, even with the extension enables, pylint still doesn't recognise 2nd level members, such as cv2.ml.KNearest_create() or cv2.ximgproc.thinning().

I believe it is the same case as #779 ?

@cipri-tom
Copy link

@cipri-tom cipri-tom commented Dec 5, 2018

@ashraf-minhaj use the Cmd+shift+p shortcut (or ctrl instead of cmd) and type "open settings (json)". There should be an option which opens the json settings and you can add the line there

@Davidnet
Copy link

@Davidnet Davidnet commented Jan 12, 2019

I'm encountering the same situation:

dgromov@Predator-G3-571 ~/D/u/s/p/CarND-Advanced-Lane-Lines> pylint camera_calibration.py --extension-pkg-whitelist=cv2 | tail                                                                                                       (SDCND) 
camera_calibration.py:157:18: E1101: Module 'cv2' has no 'undistort' member (no-member)
camera_calibration.py:159:12: E1101: Module 'cv2' has no 'imshow' member (no-member)
camera_calibration.py:160:12: E1101: Module 'cv2' has no 'waitKey' member (no-member)
camera_calibration.py:162:12: E1101: Module 'cv2' has no 'imwrite' member (no-member)
camera_calibration.py:163:12: E1101: Module 'cv2' has no 'destroyAllWindows' member (no-member)
camera_calibration.py:129:0: R1711: Useless return at end of function or method (useless-return)

----------------------------------------------------------------------
Your code has been rated at -12.67/10 (previous run: -12.67/10, +0.00)

dgromov@Predator-G3-571 ~/D/u/s/p/CarND-Advanced-Lane-Lines> conda list | grep  "pylint\|astroid"                                                                                                                                    (SDCND) 
astroid                   2.1.0                    py36_0  
pylint                    2.2.2                    py36_0  

@PCManticore
Copy link
Member

@PCManticore PCManticore commented Jan 13, 2019

As mentioned, most of the errors should be already solved by using --extension-pkg-whitelist=cv2. But unfortunately, as @cipri-tom mentioned, there are a couple of cv2 modules for which that flag does not work. I think the best way forward is for someone to propose a patch to astroid, the library that pylint uses for infererence, to add support for cv2 in a similar fashion to how we added for numpy in #779. Unfortunately we're not familiar with cv2 so it's not something that we'd do ourselves.

@mehanton
Copy link

@mehanton mehanton commented Mar 26, 2019

https://www.bilibili.com/video/av33693850/
"python.linting.pylintArgs": ["--generate-members"]

@fuzzyBatman
Copy link

@fuzzyBatman fuzzyBatman commented May 3, 2019

For me, pylint cannot process cv2 when I build cv2 from source. Works when installed using pip.

@yeknafar
Copy link

@yeknafar yeknafar commented Jun 9, 2019

@mehanton this works for me.

Thank you. :)

@LintangWisesa
Copy link

@LintangWisesa LintangWisesa commented Jun 13, 2019

  1. On VScode: CTRL + Shift + P
  2. Choose "Preferences: Open Settings (JSON)"
  3. Add this line into JSON file:
    "python.linting.pylintArgs": ["--generate-members"]
  4. Done, it works for me 👍

@githarshp
Copy link

@githarshp githarshp commented Jul 4, 2019

  1. On VScode: CTRL + Shift + P
  2. Choose "Preferences: Open Settings (JSON)"
  3. Add this line into JSON file:
    "python.linting.pylintArgs": ["--generate-members"]
  4. Done, it works for me 👍

Thanks, man! it worked for me too

@nyck33
Copy link

@nyck33 nyck33 commented Jul 23, 2019

on VSCode Ubuntu I did "python.linting.pylintArgs": ["--generate-members", "--extension-pkg-whitelist=cv2"] which worked.

@insung3511
Copy link

@insung3511 insung3511 commented Jul 28, 2019

  1. On VScode: CTRL + Shift + P
  2. Choose "Preferences: Open Settings (JSON)"
  3. Add this line into JSON file:
    "python.linting.pylintArgs": ["--generate-members"]
  4. Done, it works for me 👍

Hm.... I can't edit "defaultSetting.json file....

@LintangWisesa
Copy link

@LintangWisesa LintangWisesa commented Jul 28, 2019

  1. On VScode: CTRL + Shift + P
  2. Choose "Preferences: Open Settings (JSON)"
  3. Add this line into JSON file:
    "python.linting.pylintArgs": ["--generate-members"]
  4. Done, it works for me 👍

Hm.... I can't edit "defaultSetting.json file....

@insung3511 It must be "settings.json", not "defaultSetting.json"! Make sure you choose "Preferences: Open Settings (JSON)", not "Preferences: Open Default Settings (JSON)" 👌

@duttanaman1
Copy link

@duttanaman1 duttanaman1 commented Jul 31, 2019

thanks

@funny860
Copy link

@funny860 funny860 commented Aug 13, 2019

thanks for the help guys

@Blinue
Copy link

@Blinue Blinue commented Aug 21, 2019

The "--generate-members" option is wrong!
It works because pylint fails.
The command "pylint --generate-members test.py" fails because of "no such option: --generate-members".

@Blinue
Copy link

@Blinue Blinue commented Aug 21, 2019

Look at this, but the solution mentioned here won't work either.
It seems that the only solution is to disable the "no-member" error.

@rivergold
Copy link

@rivergold rivergold commented Oct 14, 2019

The "python.linting.pylintArgs": ["--generate-members"] is wrong, it will make pylint not work.
The correct way is to set ""python.linting.pylintArgs": ["--generated-members=cv2.*"] which only config for cv2, reference @bjtho08 reply in #779.

@t31060
Copy link

@t31060 t31060 commented Mar 6, 2020

i compiled opencv from soruce and passed the args to pylitn but still intellisense doesnt work, there is another way to solve?

@Saksham2dubey
Copy link

@Saksham2dubey Saksham2dubey commented Mar 26, 2020

I also facing the same problem of "cv2 module members are not recognized
"
what I did was
after importing cv2
write:
from cv2 import cv2
this worked for me because my JSON is not amendable

@JulianToledano
Copy link

@JulianToledano JulianToledano commented Apr 17, 2020

  1. On VScode: CTRL + Shift + P
  2. Choose "Preferences: Open Settings (JSON)"
  3. Add this line into JSON file:
    "python.linting.pylintArgs": ["--generate-members"]
  4. Done, it works for me +1

Hm.... I can't edit "defaultSetting.json file....

Now my pylint just don't show any erros 😅

@JulianToledano
Copy link

@JulianToledano JulianToledano commented Apr 17, 2020

The "python.linting.pylintArgs": ["--generate-members"] is wrong, it will make pylint not work.
The correct way is to set ""python.linting.pylintArgs": ["--generated-members=cv2.*"] which only config for cv2, reference @bjtho08 reply in #779.

Thanks that solves it.

  • On VScode: CTRL + Shift + P
  • Choose "Preferences: Open Settings (JSON)"
  • Add this line into JSON file: "python.linting.pylintArgs": ["--generated-members=cv2.*"]
  • Done, it works for me +1

@akash-falcon1999
Copy link

@akash-falcon1999 akash-falcon1999 commented Jul 16, 2020

https://www.bilibili.com/video/av33693850/
"python.linting.pylintArgs": ["--generate-members"]

works now thanks

@bjtho08
Copy link

@bjtho08 bjtho08 commented Jul 17, 2020

The "python.linting.pylintArgs": ["--generate-members"] is wrong, it will make pylint not work.
The correct way is to set ""python.linting.pylintArgs": ["--generated-members=cv2.*"] which only config for cv2, reference @bjtho08 reply in #779.

Thanks that solves it.

  • On VScode: CTRL + Shift + P
  • Choose "Preferences: Open Settings (JSON)"
  • Add this line into JSON file: "python.linting.pylintArgs": ["--generated-members=cv2.*"]
  • Done, it works for me +1

@akash-falcon1999 that pylintarg is wrong, as you can see in the above. It will make any error and any warning from pylint disappear, even those that are supposed to be there. Trust me, you don't want to pass that pylintarg. Better to live with this bug, because it actually is a bug in pylint.

@akash-falcon1999
Copy link

@akash-falcon1999 akash-falcon1999 commented Jul 17, 2020

The "python.linting.pylintArgs": ["--generate-members"] is wrong, it will make pylint not work.
The correct way is to set ""python.linting.pylintArgs": ["--generated-members=cv2.*"] which only config for cv2, reference @bjtho08 reply in #779.

Thanks that solves it.

  • On VScode: CTRL + Shift + P
  • Choose "Preferences: Open Settings (JSON)"
  • Add this line into JSON file: "python.linting.pylintArgs": ["--generated-members=cv2.*"]
  • Done, it works for me +1

@akash-falcon1999 that pylintarg is wrong, as you can see in the above. It will make any error and any warning from pylint disappear, even those that are supposed to be there. Trust me, you don't want to pass that pylintarg. Better to live with this bug, because it actually is a bug in pylint.

@bjtho08 Thanks ,rectified it,was quite bugged off with those bugs,although the code was working fine.

@rishabh547
Copy link

@rishabh547 rishabh547 commented Jul 18, 2020

  1. On VScode: CTRL + Shift + P
  2. Choose "Preferences: Open Settings (JSON)"
  3. Add this line into JSON file:
    "python.linting.pylintArgs": ["--generate-members"]
  4. Done, it works for me 👍

Do we need to install json extension in vscode for this?

@bjtho08
Copy link

@bjtho08 bjtho08 commented Jul 18, 2020

@rishabh547 see my comment above

@rishabh547
Copy link

@rishabh547 rishabh547 commented Jul 18, 2020

@rishabh547 see my comment above

So basically after adding that line in the file save the file right? That's it?

@rishabh547
Copy link

@rishabh547 rishabh547 commented Jul 18, 2020

Please help me I am low-key getting depressed because of this error, I have spent hours on this still unable to rectify!

@rishabh547
Copy link

@rishabh547 rishabh547 commented Jul 18, 2020

I tried above and still no luck.

Hey did you solve your issue? If so how

@bjtho08
Copy link

@bjtho08 bjtho08 commented Jul 20, 2020

@rishabh547 you misunderstood. The line you wrote is wrong and will make pylint fail silently, thus making it appear as if your code has zero errors. You need to use the pylint key-value argument that is written in my comment. That will solve your issue without causing pylint to fail.

@Vivraan
Copy link

@Vivraan Vivraan commented Jul 21, 2020

This doesn't seem to be bringing up cv2 in the autocomplete suggestions.
Moreoever, hovering over cv2 shows this:
image
I built opencv from source, so this points to the cv2 module under "../opencv/build/python-loader".
While the errors are all gone, no autocomplete suggestions come up. Is this intended?

@bjtho08
Copy link

@bjtho08 bjtho08 commented Jul 21, 2020

@SHIVAMMUKHERJEE autocomplete is not handled by pylint, but rather the languageserver. You will have to look at Microsofts languageserver (or jedi, if you use that one) for a solution.

@Vivraan
Copy link

@Vivraan Vivraan commented Jul 21, 2020

@bjtho08 no dice there, sigh. It's funny that the REPL somehow does this easily.

@blackhawk005
Copy link

@blackhawk005 blackhawk005 commented Aug 7, 2020

To future readers, in vsc this means adding this line to the settings:
"python.linting.pylintArgs": ["--extension-pkg-whitelist=cv2"]

how to add this line to settings???

@Vivraan
Copy link

@Vivraan Vivraan commented Aug 7, 2020

@Shinit5201
image

@blackhawk005
Copy link

@blackhawk005 blackhawk005 commented Aug 7, 2020

@kshitij-agarwal
Copy link

@kshitij-agarwal kshitij-agarwal commented Sep 4, 2020

After reading such complex tasks, I was totally surprised.

A very simple way is:
Instead of import cv2 import from cv2 import cv2

It works like a charm.

@Vivraan
Copy link

@Vivraan Vivraan commented Sep 4, 2020

After reading such complex tasks, I was totally surprised.

A very simple way is:
Instead of import cv2 import from cv2 import cv2

It works like a charm.

You could also take a step further and import even more granularly into individual classes or features instead of the whole module!

@kritikaparmar-programmer

After reading such complex tasks, I was totally surprised.

A very simple way is:
Instead of import cv2 import from cv2 import cv2

It works like a charm.

It worked dude!!😁

meashishsaini added a commit to meashishsaini/up_scholarship that referenced this issue Sep 19, 2020
For cv2 reference: PyCQA/pylint#2426

Signed-off-by: Ashish Saini <sainiashish08@gmail.com>
@slugb0t
Copy link

@slugb0t slugb0t commented Sep 26, 2020

After reading such complex tasks, I was totally surprised.

A very simple way is:
Instead of import cv2 import from cv2 import cv2

It works like a charm.

a simple solution wow thank you

@zchrissirhcz
Copy link

@zchrissirhcz zchrissirhcz commented Sep 28, 2020

"python.linting.pylintArgs": ["--generate-members"] works for me.

Btw, tts 2020-09-28 already, why people still have to setup this stuff for pylint?

@bjtho08
Copy link

@bjtho08 bjtho08 commented Sep 28, 2020

"python.linting.pylintArgs": ["--generate-members"] works for me.

Btw, tts 2020-09-28 already, why people still have to setup this stuff for pylint?

That argument is wrong and will make pylint fail silently. See the comments earlier in the thread for an explanation.

@jofrev
Copy link

@jofrev jofrev commented Oct 11, 2020

After reading such complex tasks, I was totally surprised.

A very simple way is:
Instead of import cv2 import from cv2 import cv2

It works like a charm.

It won't report an error in VS Code's problems tab any longer that's true. But if you run pylint from your terminal you'll still get

I1101: Module 'cv2.cv2' has no 'imread' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member)

with from cv2 import cv2 instead of

E1101: Module 'cv2' has no 'imread' member (no-member)

with import cv2. Depending on how one intends to use pylint, whitelisting cv2 in pylint settings as described numerous times above may actually be better.

@gautamjain1009
Copy link

@gautamjain1009 gautamjain1009 commented Oct 14, 2020

@Shinit5201
image

this is not working for me I am using Opencv 4.1.0 build from source in an anaconda environment.

@Mechazo11
Copy link

@Mechazo11 Mechazo11 commented Nov 28, 2020

  1. On VScode: CTRL + Shift + P
  2. Choose "Preferences: Open Settings (JSON)"
  3. Add this line into JSON file:
    "python.linting.pylintArgs": ["--generate-members"]
  4. Done, it works for me 👍

Worked for me too. Thanks

@ardf
Copy link

@ardf ardf commented Apr 29, 2021

I also facing the same problem of "cv2 module members are not recognized
"
what I did was
after importing cv2
write:
from cv2 import cv2
this worked for me because my JSON is not amendable

Thanks! worked for me too

@nnmrts
Copy link

@nnmrts nnmrts commented Sep 5, 2021

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.

@domajstorovic
Copy link

@domajstorovic domajstorovic commented Nov 12, 2021

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
Copy link

@KukavicaHome KukavicaHome commented Feb 19, 2022

VS2019 works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests