Closed uriva closed 6 years ago
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.
To future readers, in vsc this means adding this line to the settings:
"python.linting.pylintArgs": ["--extension-pkg-whitelist=cv2"]
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 ?
@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
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
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.
https://www.bilibili.com/video/av33693850/ "python.linting.pylintArgs": ["--generate-members"]
For me, pylint cannot process cv2 when I build cv2 from source. Works when installed using pip.
@mehanton this works for me.
Thank you. :)
"python.linting.pylintArgs": ["--generate-members"]
- On VScode: CTRL + Shift + P
- Choose "Preferences: Open Settings (JSON)"
- Add this line into JSON file:
"python.linting.pylintArgs": ["--generate-members"]
- Done, it works for me 👍
Thanks, man! it worked for me too
on VSCode Ubuntu I did "python.linting.pylintArgs": ["--generate-members", "--extension-pkg-whitelist=cv2"]
which worked.
- On VScode: CTRL + Shift + P
- Choose "Preferences: Open Settings (JSON)"
- Add this line into JSON file:
"python.linting.pylintArgs": ["--generate-members"]
- Done, it works for me 👍
Hm.... I can't edit "defaultSetting.json file....
- On VScode: CTRL + Shift + P
- Choose "Preferences: Open Settings (JSON)"
- Add this line into JSON file:
"python.linting.pylintArgs": ["--generate-members"]
- 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)" 👌
thanks
thanks for the help guys
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".
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.
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.
i compiled opencv from soruce and passed the args to pylitn but still intellisense doesnt work, there is another way to solve?
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
- On VScode: CTRL + Shift + P
- Choose "Preferences: Open Settings (JSON)"
- Add this line into JSON file:
"python.linting.pylintArgs": ["--generate-members"]
- Done, it works for me +1
Hm.... I can't edit "defaultSetting.json file....
Now my pylint just don't show any erros :sweat_smile:
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 forcv2
, reference @bjtho08 reply in #779.
Thanks that solves it.
"python.linting.pylintArgs": ["--generated-members=cv2.*"]
I tried above and still no luck.
https://www.bilibili.com/video/av33693850/ "python.linting.pylintArgs": ["--generate-members"]
works now thanks
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 forcv2
, 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.
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 forcv2
, 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.
- On VScode: CTRL + Shift + P
- Choose "Preferences: Open Settings (JSON)"
- Add this line into JSON file:
"python.linting.pylintArgs": ["--generate-members"]
- Done, it works for me 👍
Do we need to install json extension in vscode for this?
@rishabh547 see my comment above
@rishabh547 see my comment above
So basically after adding that line in the file save the file right? That's it?
Please help me I am low-key getting depressed because of this error, I have spent hours on this still unable to rectify!
I tried above and still no luck.
Hey did you solve your issue? If so how
@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.
This doesn't seem to be bringing up cv2
in the autocomplete suggestions.
Moreoever, hovering over cv2 shows this:
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?
@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.
@bjtho08 no dice there, sigh. It's funny that the REPL somehow does this easily.
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???
@Shinit5201
Thanks
On 07-Aug-2020, at 10:51 AM, Shivam Mukherjee notifications@github.com wrote:
@Shinit5201 https://github.com/Shinit5201 https://user-images.githubusercontent.com/12777564/89611882-ea42d380-d89b-11ea-959c-92d43a821240.png — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PyCQA/pylint/issues/2426#issuecomment-670328080, or unsubscribe https://github.com/notifications/unsubscribe-auth/APVLRH3TAOJMCQRBJZ5VC33R7OFN3ANCNFSM4FQPTXBA.
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.
After reading such complex tasks, I was totally surprised.
A very simple way is: Instead of
import cv2
importfrom 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!
After reading such complex tasks, I was totally surprised.
A very simple way is: Instead of
import cv2
importfrom cv2 import cv2
It works like a charm.
It worked dude!!😁
After reading such complex tasks, I was totally surprised.
A very simple way is: Instead of
import cv2
importfrom cv2 import cv2
It works like a charm.
a simple solution wow thank you
"python.linting.pylintArgs": ["--generate-members"]
works for me.
Btw, tts 2020-09-28 already, why people still have to setup this stuff for pylint?
"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.
After reading such complex tasks, I was totally surprised.
A very simple way is: Instead of
import cv2
importfrom 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.
@Shinit5201
this is not working for me I am using Opencv 4.1.0 build from source in an anaconda environment.
- On VScode: CTRL + Shift + P
- Choose "Preferences: Open Settings (JSON)"
- Add this line into JSON file:
"python.linting.pylintArgs": ["--generate-members"]
- Done, it works for me 👍
Worked for me too. Thanks
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
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.
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