Fix pyrIght warning "Import [module] could not be resolved"?

1.1k Views Asked by At

I have the following Projects folder structure:

enter image description here

and the file Tasks/Scripts/test.py (shown below) attaches util.py from Libs/PyLibs:

enter image description here

The file test.py executes fine without any issue, but I cannot get rid of the import warning (I am using latest neovim with lsp/mason/null-ls plugins). Similar issues were reported here and here, but none of the methods suggested there, for example putting a pyrightconfig.json or pyproject.toml file in the project root with appropriate config settings, is working for me, maybe because I have a somewhat more complex folder structure.

Any help is greatly appreciated. Thanks!

1

There are 1 best solutions below

0
On

You can add extraPaths to pyrightconfig.json:

{
  "extraPaths": ["/home/roy/Projects/Libs/PyLibs/"]
}

extraPaths [array of strings, optional]: Additional search paths that will be used when searching for modules imported by files. - Pyright Main Configuration Options