You should create a pyrightconfig.json file or pyproject.toml file at the root of your project. For example, if it's a Django project, you should have one of those files where manage.py is placed. Then, set include parameter and add the subdirectories (or app folders in Django terms).
You can consult this sample config file. See this issue ticket.
For example, if this were my project structure:
├── manage.py
├── movie
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── moviereviews
│ ├── asgi.py
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── pyproject.toml
my pyproject.toml would be:
[tool.pyright]
include = ["movie", "moviereviews"]
If you are working within a Python virtual environment, set venvPath and venv. Consult the documentation for an exhaustive list of options.
Answer from harsath on Stack OverflowYou should create a pyrightconfig.json file or pyproject.toml file at the root of your project. For example, if it's a Django project, you should have one of those files where manage.py is placed. Then, set include parameter and add the subdirectories (or app folders in Django terms).
You can consult this sample config file. See this issue ticket.
For example, if this were my project structure:
├── manage.py
├── movie
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── moviereviews
│ ├── asgi.py
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── pyproject.toml
my pyproject.toml would be:
[tool.pyright]
include = ["movie", "moviereviews"]
If you are working within a Python virtual environment, set venvPath and venv. Consult the documentation for an exhaustive list of options.
Ok, a relative import as illustrated here was able to solve this. So in my case I should have
# MyModule_test.py
import pytest
from .. import MyModule
As the title says, I am running into a weird situation with pyright in neovim. The pyright LSP is attached to my session and diagnoses an `import could not be resolved error` error. (https://gyazo.com/2ccaa53a09a6908ed99e83814458ec28).
However, when I run the `main.py` file everything works as expected. When I change the absolute import in the `another_module.py` to `from ..folder.module import hello_world` the diagnosis disappears. The code however then throws an ImportError `attempted relative import beyond top-level package`. Referring to the `..folder.module import hello_world` line. This is my `main.py` file: https://gyazo.com/10125d588b6247a79ea6c809acccda08
Anyone has any idea what is going on or has run into this before?
python - "Import could not be resolved" reported by Pyright - Stack Overflow
Pyright "import ' ' cannot not be resolved" identifying imports inside python packages
Import could not be resolved
Pyright unable to resolve imports that are in my PYTHONPATH
What are common causes of the 'pyright import could not be resolved' error?
What does the error indicating that the pyright import could not be resolved mean?
How can Kodezi help with resolving pyright import issues?
On my computer I have 3 Pythons, a 3.6 from Anaconda, and a 2.7 & 3.7 that are regular python. Prompted by a nudge from this GH issue, I switched from the Anaconda 3.6 to the 3.7, and back again, and the problem went away.

I think that this is the case because your .vscode/settings.json (the following is mine), doesn't have that last line until you change your python, at which point, that last line is put in and Pyright has something to look at.
{
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.pythonPath": "C:\\Users\\ben\\Anaconda3\\python.exe"
}
python -m pip install -U pylint
python -m pip install --upgrade pip
Open VS Code -> CTRL + SHIFT P -> Search 'select linter' [Python: Select Linter] -> Hit Enter and Select Pylint
If not solved.
Try deactivate your environment pip install numpy in your global environment.
And if you are using Local Environment getting unresolved imports error then add In .vscode/settings.json "python.analysis.extraPaths": ["./path-to-your-code"], for example "python.analysis.extraPaths": [ "*.lib" ]
I'm running into what seems to be a rather common problem with `Pyright` where it's unable to resolve an import. For example, I am getting Pyright: Import "iterm2" could not be resolved.
For reference, I am using the default Pyright configs just to keep things simple. My directory structure also looks something like this:
RootDir/
- Dir
- Dir
- Scripts
- myFile.py # Where the import error arises
- OtherDirs
- setup.cfg
When I do an :LspInfo I see that the LSP is attached, and it tends to work for the standard library, just not for other imports.
From the research I have done thus far, it seems like every Python project you work on requires a unique pyrightconfig.json file, which to me seems like I may be misreading what I have found because it feels cumbersome.
I know that you can modify the LSP settings for Pyright as in the link above, but do you also require a project-based file in addition to the LSP settings for Pyright to properly understand imports?