How do you make pylint in VSCode know that it's in a package (so that relative imports work)? How do you make pylint in VSCode know that it's in a package (so that relative imports work)? python-3.x python-3.x

How do you make pylint in VSCode know that it's in a package (so that relative imports work)?


Currently pylint cannot find modules accurately through relative imports, it will mess up the path, although the code can run.

You could try the following two ways to solve it:

1.Add the following settings in the setting.json file.

"python.linting.pylintArgs":   ["--disable=all",     "--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode",    "--disable=E0402",   ],

(Since there is no issue with the code, we can turn off this type of pylint prompt.)

  1. Since the relative import method will make pylint confusing, we can avoid such use.

    Use 'from foo import harr' instead of 'from .foo import harr'.

Reference: Default Pylint rules.


I suffered from the same issue earlier this morning.

It turns out than you can just add init .py file in your root path.

workspace/    .vscode/launch.json    __init__.py    main.py    foo.py