Detect unused imports in visual studio code for python 3?

It only highlights the unused imports but not automatically removes them.

"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--enable=W0614"],
"[python]": {
"editor.codeActionsOnSave": {
  "source.organizeImports": true
}},

Version: 1.37.1 (user setup) Date: 2019-08-15T16:17:55.855Z Electron: 4.2.7 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8: 6.9.427.31-electron.0 OS: Windows_NT x64 10.0.16299


The Python extension for VS Code does not support warning about unused imports in its language server yet. But if you want Pylint to warn you, create a .pylintrc and and turn on the W0611 warning.


Visual studio code has released a new feature last year in April in 2018 which allow users to change their settings to remove unused imports automatically on save. Personally I have tried to configure both JavaScript and TypeScript and it works great out of box, so I'll assume it should also work for Python since you can enable/disable by using the language setting, please try updating your setting.json file with the following new changes:

"editor.formatOnSave": true,
"[python]": {
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    }
},

Hopefully this could work on your Python project! Good luck!


Update/create VSCode user settings

"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
    "--enable=W0614"
]

this works for me in Python 3.6.7 / 3.6.8