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 · 19 comments
Closed

cv2 module members are not recognized #2426

uriva opened this issue Aug 20, 2018 · 19 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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

@mehanton mehanton commented Mar 26, 2019

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

@fuzzyBatman

This comment has been minimized.

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

This comment has been minimized.

Copy link

@yeknafar yeknafar commented Jun 9, 2019

@mehanton this works for me.

Thank you. :)

@LintangWisesa

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

@duttanaman1 duttanaman1 commented Jul 31, 2019

thanks

@funny860

This comment has been minimized.

Copy link

@funny860 funny860 commented Aug 13, 2019

thanks for the help guys

@Blinue

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.