27

That's my user settings in vscode

{
  "python.pythonPath": "/Users/cristiano/miniconda3/envs/django-rest-2/bin/python",
  "python.linting.pylintEnabled": true,
  "python.linting.enabled": true,
  "python.linting.pylintArgs": [
    "--load-plugins",
    "pylint_django"
  ],
}

I installed the plugin via conda, same as the pylint

pylint                    2.1.1                    py36_0
pylint-django             0.11.1                     py_1    conda-forge
pylint-plugin-utils       0.4                        py_0    conda-forge

If i commented out the "python.linting.pylintArgs" section, pylint works with no problem. I ned to enable the plugin to avoid django-specific errros such as "Entity.objects.all()", but if I enable it, the lint stop working: it does not highlight standard errors o warning the previously was doing it.

I have same exact behaviour using vscode for win and mac. I tried also to use the .pylintrc file as described here but I have the same result: lint stop working. Same behaviour using base conda env or a custom one.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Crixo
  • 3,060
  • 1
  • 24
  • 32
  • That looks right and wfm, so I would say your problem is with your pythonPath and environment. – J0hnG4lt Feb 07 '19 at 14:51
  • 4
    @Crixo - have you managed to resolve this? I'm experiencing the same problem no matter which configuration I try. – zerohedge May 12 '19 at 06:15
  • For me, installing the plugin (pylint-django) via pip instead of conda solved the issue. – Tom Nov 01 '19 at 16:15
  • 1
    I managed to get the error message which solved this for me, by running the pylint command shown in VSCode output python, directly in the terminal. At that point I got an exception and was able to solve the problem. – Dominic Woodman Jan 29 '20 at 01:10

9 Answers9

22

This config for pylint is working for me:

"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
    "--disable=C0111", // missing docstring
    "--load-plugins=pylint_django,pylint_celery",
 ],
Manu Artero
  • 9,238
  • 6
  • 58
  • 73
4

I just got the same issue. Like @J0hnG4lt said, I had a problem with the python path. I didn't point to the path of the environment, which I have installed pylint_django. This config is work for me. Thanks @Manu.

"python.pythonPath": "/Users/mc976/Documents/Programming/Python/Practice/music_service/venv/bin/python3",
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
    "--disable=C0111",
    "--load-plugins",
    "pylint_django"
]

Besides, I think you should check your environment to make sure that you have correctly installed pylint_django by using pip list.

Thuc Pham
  • 153
  • 1
  • 11
  • Tx! I only required `{ "python.linting.pylintArgs": [ "--load-plugins", "pylint_django", "--django-settings-module=myapp.settings" ] }` – ptim May 29 '23 at 07:34
  • actually, the missing link was `--django-settings-module=myapp.settings` - added an answer below https://stackoverflow.com/a/76355494/2586761 – ptim May 29 '23 at 07:44
2

My issue was more prosaic (but perhaps it will help other forehead slappers like myself). Run the PIP install in the correct virtualenv directory!

pip install pylint-django --upgrade

Also note that plugin errors cause Pylint to completely fail to load silently. Start with blank pylintArgs and slowly add them back one at a time to see where things go awry.

Neil C. Obremski
  • 18,696
  • 24
  • 83
  • 112
  • This was also the correct answer for me. I had installed it globally, but wasn't really thinking that it was my local env interpreter which was doing the linting. – Dominic Woodman Jan 29 '20 at 01:09
2

python.pythonPath is deprecated. You should use python.defaultInterpreterPath instead

aldwinp35
  • 109
  • 1
  • 7
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33532716) – He3lixxx Jan 01 '23 at 22:42
1

found a working answer for myself here: https://donjayamanne.github.io/pythonVSCodeDocs/docs/linting/

my settings.json file now reads:

{
    "python.pythonPath": "C:\\ProgramData\\Anaconda3\\envs\\djangoSite2\\python.exe",
    "python.linting.pylintEnabled": true,
    "python.linting.pylintArgs": ["--disable=C0111","--load-plugins", "pylint_django"],
}

this then adds linting, but doesn't throw an error on fields that it can't find (like the Entity.objects.all() one), but has the disadvantage that if you then try and reference something that really doesn't exist it doesn't throw an error.

KaiuTetsuo
  • 306
  • 2
  • 4
1

It now works on my Mac. This is my workspace's settings.json:

{
"python.linting.pylintEnabled": true,
"python.linting.pycodestyleEnabled": false,
"files.autoSave": "afterDelay",
"editor.fontSize": 14,
"editor.wordWrapColumn": 90,
"editor.autoClosingQuotes": "beforeWhitespace",
"python.pythonPath": "/Users/myname/anaconda3/envs/myproject/bin/python",
"python.linting.pylintArgs": [
    "--disable=C0111", // missing docstring
    "--load-plugins=pylint_django",
 ],

}

I had to be careful to have installed pylint-django into the correct python environment. For me, this meant running this command in the terminal:

$ /Users/myname/anaconda3/envs/myproject/bin/python -m install pip pylint pylint-django

tyrex
  • 8,208
  • 12
  • 43
  • 50
0

I ran into an error related to pylint not being able to parse JSON correctly. All I had to do was add an 's' to my config to make it plugins (plural) instead of plugin. Then everything started working.

"python.linting.pylintArgs": [
            "--load-plugins=pylint_django",
        ],
John Solly
  • 326
  • 2
  • 7
0

create a new file .pylintrc and add this script

[MASTER]
disable=bad-plugin-value
Muhammadalive
  • 648
  • 5
  • 5
0

My setup needed a details missing from other answers, namely the correct settings module:

// .vscode/settings.json
{
  "python.linting.pylintArgs": [
    "--load-plugins",
    "pylint_django",
    "--django-settings-module=myapp.settings"
  ]
}

The linter hints at the solution in places, instructing you to execute:

pylint --load-plugins=pylint_django --help-msg=django-not-configured

...which produces:

:django-not-configured (E5110): Django was not configured. For more information run pylint --load-plugins=pylint_django --help-msg=django-not-configured

Finding foreign-key relationships from strings in pylint-django requires configuring Django. This can be done via the DJANGO_SETTINGS_MODULE environment variable or the pylint option django-settings-module, eg: pylint --load-plugins=pylint_django --django-settings-module=myproject.settings .

This can also be set as an option in a .pylintrc configuration file. Some basic default settings were used, however this will lead to less accurate linting. Consider passing in an explicit Django configuration file to match your project to improve accuracy. This message belongs to the django foreign keys referenced by strings checker.

Docs: https://github.com/landscapeio/pylint-django#usage

ptim
  • 14,902
  • 10
  • 83
  • 103