15

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?

User
  • 1,098
  • 9
  • 28
Evan Kim
  • 739
  • 1
  • 6
  • 22
  • Is it an option to switch to a different linter? Similar errors went away for me when I switched to flake8 in vscode: CTRL + Shift + P `Python: Select Linter`->`flake8`. – teichert Jun 02 '20 at 18:38

5 Answers5

53
  1. Press: CTRL + Shift + P

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

  3. Add this line into JSON : "python.linting.pylintArgs": ["--generated-members", "from_json,query"]


Ken
  • 3,937
  • 3
  • 24
  • 39
Vaitul Bhayani
  • 586
  • 5
  • 4
  • 9
    Does this really work, though? I edited my JSON with that and pylint stopped working completely. – RGS Apr 17 '20 at 17:02
  • Thank you. This solved my issue on Visual Studio Code. – Tin Nguyen May 26 '20 at 19:34
  • @RGS, It worked for me. Are you sure you didn't forget the comma at the end of the line above where you inserted the line from #3 above? – SoCalCoder May 27 '20 at 22:54
  • 2
    @SoCalCoder I am... :/ – RGS May 28 '20 at 09:26
  • 3
    @SoCalCoder, is it possible that you forgot the 'd' in '--generated-members'? I believe there's a typo in the answer above. – Steven Darnell Jul 20 '20 at 20:10
  • @StevenDarnell it is a typo indeed. According to pylint's help message (`pylint --long-help`) it should be `--generated-members=member1,member2,member3`. So, correct line in VSCode's settings JSON should be `"python.linting.pylintArgs": ["--generated-members", "from_json,query"]` – vocasle Oct 28 '20 at 07:51
8

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.*"
]
RGS
  • 752
  • 2
  • 8
  • 23
7

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

Alex
  • 370
  • 3
  • 7
  • Could anyone share more details about this? I cannot find the `Scripts` directory under my `(You Anaconda Path)\pkgs\pylint-xxx-xxx` path. – Boooooooooms Oct 17 '20 at 08:49
  • @Boooooooooms Same! Could you please let me know how did you fixed this issue? Thanks! – Pressing_Keys_24_7 Jan 13 '21 at 05:09
  • This one solve my problem. VS code updated and pointed my pylint to the base version instead of the environment version. I try modifiying the setting json and that did not work – CaribeGirl Jun 16 '21 at 22:03
  • The Scripts folder exist in Windows, Not sure if in a different OS will be different. In general you are looking the pylint.exe. If it is not there then I think you need to `pip intall pylint ` – CaribeGirl Jun 16 '21 at 22:08
1

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:

  1. Hit CTRL + Shift + P

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

  3. 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 ]

audioTech
  • 11
  • 1
0

As Tomari says, it does work 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".

jieke
  • 1
  • 1
  • 3