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?
Press: CTRL + Shift + P
Click on "Preferences: Open Settings (JSON)"
Add this line into JSON : "python.linting.pylintArgs": ["--generated-members", "from_json,query"]
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
What worked for me was noticing what modules were giving those errors, which is torch
for you, and then followed these steps:
"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.*"
]
A better answer to this question here: Why does it say that module pygame has no init member?
The answer above marked as the answer with references to Anaconda doesn't make sense to me, probably a newbie issue.
Please follow the link to get the real scoop, but to summarize -
Replacing extensionname with your problem module name, such as pygame or RPi or Torch:
Hit CTRL + Shift + P
Click on "Preferences: Open Settings (JSON)"
Add the following to the JSON file you are presented with (inside the {}, if there are entries already there add leading comma as well):
"python.linting.pylintArgs": [ "--extension-pkg-whitelist=extensionname" // comma separated ]
As Tomari says, it does works on windows.There is a little difference on linux. The path maybe like "(You Anaconda Path)/pkgs/pylint-2.6.0-py38_0/bin/pylint".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.