My VSCode doesn’t recognize modules and libraries imported in Python scripts, and shouts Unable to import ### PylintE0401:import-error
at every single module import statement.
The Python scripts run without any issues. I’m always initializing poetry shell by running poetry shell
and it’s always activated. So I’m sure PyLint is pointing to a wrong interpreter, but I don’t know what I should put in what settings.
Here are some of the command outputs.
poetry env list
.venv (Activated). -> I'm choosing this environment in settings (Python: Select Interpreter)
poetry env info --path
/Users/makotomiyazaki/repos/Sakana/writing-assistant/.venv
poetry config virtualenvs.path
/Users/makotomiyazaki/Library/Caches/pypoetry/virtualenvs
2
Answers
I had a similar issue, but after I had closed vscode and restarted it the pylint message had resolved itself.
First, make sure that you have selected the correct Python interpreter for your project, e.g. by using the
Python: Select Interpreter
command.Next, open your settings and search for
Pylint
. Locate thePylint: Import Strategy
option, and choosefromEnvironment
.