pylint no member issue but code still works vscode

ε祈祈猫儿з 提交于 2020-08-08 04:31:46

问题


I have a very simple code here

import torch

l = torch.nn.Linear(2,5)
v = torch.FloatTensor([1, 2])
print(l(v))

under torch.FloatTensor, pylint in visual studio code claims that 'Module torch has no 'FloatTensor' member pylint(no-member).

However, the code works fine. Is this a false positive? How can I disable pylint for this specific instance?


回答1:


Yes it is a problem of Pylint

If you use Anaconda, you can do:
1. search python.linting.pylintPath in your VSCode setting
2. change it to (You Anaconda Path)\pkgs\pylint-1.8.4-py36_0\Scripts\pylint

You Anaconda Path and pylint-1.8.4-py36_0 may vary




回答2:


  1. Press: CTRL + Shift + P

  2. Click on "Preferences: Open Settings (JSON)"

  3. Add this line into JSON : "python.linting.pylintArgs": ["--generate-members"]





回答3:


What worked for me was noticing what modules were giving those errors, which is torch for you, and then followed these steps:

  1. hit CTRL + Shift + P
  2. click on "Preferences: Open Settings (JSON)"
  3. add the following to the JSON file you are presented with:
"python.linting.pylintArgs": [
    "--generated-members", "torch.*"
]

for the sake of this answer, say that there were other modules giving problems, then you'd write:

"python.linting.pylintArgs": [
    "--generated-members", "torch.* other_module.* next_module.*"
]


来源:https://stackoverflow.com/questions/56844378/pylint-no-member-issue-but-code-still-works-vscode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!