VSCode Pylint eliminates the red wavy lines in OpenCV PyTorch and other programs

This article is reproduced from the blog , thank you very much for the blogger who solved the corresponding problem.

Preface

VSCode version

I am using the latest version of VSCode under Windows10: June 2020 (version 1.47)
Insert picture description here

problem

Install VSCode after installing Anaconda, and install Pylint by default. And what is Pylint , here is a quote from the blog : pylint is
a PYTHON module that is mainly used to analyze your PY code, find out the errors, and give tips, and it can also provide you with some coding style tips. In short, its role is to make your code closer to the code style described in PEP 008 (http://www.python.org/dev/peps/pep-0008/) Title: Style Guide for Python Code. Your code is unified and more readable.

It's very convenient to use, but the only unfriendly thing is that it can't recognize packages outside of it, such as the common opencv and pytorch, which is a headache for me, because every time cv2 and torch appear, there are below them A red wavy line makes the box on the right of VSCode all red. Obsessive-compulsive disorder means uncomfortable. The biggest problem is that it buried real grammatical errors, making it difficult to find them! The effect is like this:
Insert picture description here
as long as there are torch and cv2, there will be red wavy lines, which is a headache

Common incorrect handling

1

Open Baidu search: vscode pylint OpenCV red squiggles, the first blog that appeared is: to solve the problem of calling cv2 in VSCode, the code always shows red squiggles, he said to search for pylintargs in VSCode settings, and then add a sentence:

"python.linting.pylintArgs": ["--generate-members"]

   
    
    
  • 1

But the json file is no longer visible in the new version of VSCode, I added it according to the comment:

--generate-members

   
    
    
  • 1

As follows:
Insert picture description here
I see many blogs that say so, for example:
https://blog.csdn.net/ngy321/article/details/88972255
https://blog.csdn.net/zaf0516/article/details/95635658

I tried it immediately and found that the red wavy line is indeed absent, but all the prompts are gone, like uninstalling pylint, like this:
Insert picture description here
but this is not my purpose, I want to find the real error!

2

I saw a blog criticizing the above approach: Vscode Pylint no-member , he said that the above stuff is wrong, it should be:

--generated-members

   
    
    
  • 1

It should not be –generate-members.

After changing happily, I found that it was still fruitless...

I also installed the method recommended by him: install pylint-django

pip install pylint-django

   
    
    
  • 1

Then write in the place of –generated-members:

--load-plugins=pylint_django

   
    
    
  • 1

The result is that there are no red wavy lines, but there are many blue wavy lines for unknown reasons: the
Insert picture description here
problem is still not solved

Solution

Until I saw an approach on GitHub :
Insert picture description here
that is, add:

--errors-only
--generated-members=numpy.* ,torch.* ,cv2.* , cv.*

   
    
    
  • 1
  • 2

Insert picture description here
The current effect:
Insert picture description here
This solves my problem very well. The red wavy lines about cv2 and torch are gone, only revealing my real mistakes, which is great.
Borrow a comment from one person: You saved part of my life!
Insert picture description here
thank

Preface

VSCode version

I am using the latest version of VSCode under Windows10: June 2020 (version 1.47)
Insert picture description here

problem

Install VSCode after installing Anaconda, and install Pylint by default. And what is Pylint , here is a quote from the blog : pylint is
a PYTHON module that is mainly used to analyze your PY code, find out the errors, and give tips, and it can also provide you with some coding style tips. In short, its role is to make your code closer to the code style described in PEP 008 (http://www.python.org/dev/peps/pep-0008/) Title: Style Guide for Python Code. Your code is unified and more readable.

It's very convenient to use, but the only unfriendly thing is that it can't recognize packages outside of it, such as the common opencv and pytorch, which is a headache for me, because every time cv2 and torch appear, there are below them A red wavy line makes the box on the right of VSCode all red. Obsessive-compulsive disorder means uncomfortable. The biggest problem is that it buried real grammatical errors, making it difficult to find them! The effect is like this:
Insert picture description here
as long as there are torch and cv2, there will be red wavy lines, which is a headache

Common incorrect handling

1

Open Baidu search: vscode pylint OpenCV red squiggles, the first blog that appeared is: to solve the problem of calling cv2 in VSCode, the code always shows red squiggles, he said to search for pylintargs in VSCode settings, and then add a sentence:

"python.linting.pylintArgs": ["--generate-members"]

   
  
  
  • 1

But the json file is no longer visible in the new version of VSCode, I added it according to the comment:

--generate-members

   
  
  
  • 1

As follows:
Insert picture description here
I see many blogs that say so, for example:
https://blog.csdn.net/ngy321/article/details/88972255
https://blog.csdn.net/zaf0516/article/details/95635658

I tried it immediately and found that the red wavy line is indeed absent, but all the prompts are gone, like uninstalling pylint, like this:
Insert picture description here
but this is not my purpose, I want to find the real error!

2

I saw a blog criticizing the above approach: Vscode Pylint no-member , he said that the above stuff is wrong, it should be:

--generated-members

   
  
  
  • 1

It should not be –generate-members.

After changing happily, I found that it was still fruitless...

I also installed the method recommended by him: install pylint-django

pip install pylint-django

   
  
  
  • 1

Then write in the place of –generated-members:

--load-plugins=pylint_django

   
  
  
  • 1

The result is that there are no red wavy lines, but there are many blue wavy lines for unknown reasons: the
Insert picture description here
problem is still not solved

Solution

Until I saw an approach on GitHub :
Insert picture description here
that is, add:

--errors-only
--generated-members=numpy.* ,torch.* ,cv2.* , cv.*

   
  
  
  • 1
  • 2

Insert picture description here
The current effect:
Insert picture description here
This solves my problem very well. The red wavy lines about cv2 and torch are gone, only revealing my real mistakes, which is great.
Borrow a comment from one person: You saved part of my life!
Insert picture description here
thank

Guess you like

Origin blog.csdn.net/weixin_39536859/article/details/108653676