That is a Pylance error.
You can create a pyrightconfig.json file at the root of your workspace and define the files to be exclude-d from analysis or completely ignore-d:
{
"ignore": [
"**/*.ipynb",
],
}
You can even list up specific filenames:
{
"ignore": [
"notimportant.ipynb",
"test.ipynb",
],
}
Historical Notes:
It initially didn't work for Jupyter Notebooks (.ipynb):
https://github.com/microsoft/pylance-release/issues/2135
This happens because pyright doesn't see the file as a "*.ipynb". The file is being preprocessed (to combine all of the cells) in the notebook by the VS Code Python extension, and the resulting combined file is then passed to pyright for analysis.
The pylance team is actively working on changing the way this works. I'm going to transfer this bug to the pylance-release repo so it gets the attention it deserves.
That Github issue has since been resolved the fix was deployed as part of pylance 2022.8.51: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#2022851-31-august-2022-prerelease
Notable changes:
- ...
- Bug Fix: Ignoring *.ipynb files does not work (pylance-release#2135)
If it somehow still does not work, check the version of pylance on your VS Code.
Answer from Gino Mempin on Stack Overflow
For example __init__.py imports
Disable specific Pylance linting messages in VS Code settings.json like with "python.linting.pylintArgs" - Stack Overflow
Ignore flag for files and folders
Allow line level suppression of specific errors
visual studio code - Ignore Pylance missing imports - Stack Overflow
That is a Pylance error.
You can create a pyrightconfig.json file at the root of your workspace and define the files to be exclude-d from analysis or completely ignore-d:
{
"ignore": [
"**/*.ipynb",
],
}
You can even list up specific filenames:
{
"ignore": [
"notimportant.ipynb",
"test.ipynb",
],
}
Historical Notes:
It initially didn't work for Jupyter Notebooks (.ipynb):
https://github.com/microsoft/pylance-release/issues/2135
This happens because pyright doesn't see the file as a "*.ipynb". The file is being preprocessed (to combine all of the cells) in the notebook by the VS Code Python extension, and the resulting combined file is then passed to pyright for analysis.
The pylance team is actively working on changing the way this works. I'm going to transfer this bug to the pylance-release repo so it gets the attention it deserves.
That Github issue has since been resolved the fix was deployed as part of pylance 2022.8.51: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#2022851-31-august-2022-prerelease
Notable changes:
- ...
- Bug Fix: Ignoring *.ipynb files does not work (pylance-release#2135)
If it somehow still does not work, check the version of pylance on your VS Code.
Gino's solution doesn't work for me as of VSCode 1.88.1 + Pylance v2024.4.1.
What worked for me was adding the following to my pyproject.toml:
[tool.pyright]
exclude = ["**/*ipynb"]
insert this:
# type: ignore
paste it at the top of the file to ignore the file
paste it at the end of a line to ignore the line
Reference: https://www.reddit.com/r/VisualStudioCode/comments/i3mpct/comment/g5bkx9u/
Add this to your settings.json:
"python.analysis.diagnosticSeverityOverrides": {
"reportMissingImports": "none"
}
You can add the following settings in settings.json configuration file:
"python.analysis.diagnosticSeverityOverrides": { "reportUndefinedVariable": "none" }
Or you can search for python.analysis.diagnosticSeverityOverrides in the settings, click Add Item button to select "reportUndefinedVariable", "none":

Result:

Following the issue that @Jill Cheng linked in the comments, the pylance devs suggest using a # type: ignore comment after the line in question. You will lose out on other linting abilities for this line though so apply with caution.
As a side note, if you're using this to quiet the messages due to "import <module> could not be resolved" then you should look into correctly configuring your workspace rather than overriding the message. Here's an example answer to help you solve that issue.
I coach a robotics team of middle school kids and it is important that all of the laptops are configured the same. When we clone our repo, VS Code will prompt them to enable type checking. I'd rather keep type checking off for now, so I really much prefer the warning to not come up at all. The kids are kind of quick to hit the default "Yes", which enables type checking. I have in my pyproject.toml
```
[tool.pyright] typeCheckingMode = "off"
```
And that is included in the repo. And even so, I still get the warning/suggestion
"Pylance has detected type annotations in your code and recommends enabling type checking. Would you like to change this setting?"
Sure, I can click "No" at that point, and it seems to keep pylance happy and it doesn't ask again, but I'd rather it not ask at all in the first place. Ideally I'd like to figure out a way to suppress the warning at the project level, so I can push the setting to everyone as part of the repo.