You may search for settings about additional import search resolution paths:
"python.analysis.extraPaths": [
"path1",
"path2",
],
Please have a try.
More information view Pylance Settings and Customization.
Answer from Molly Wang-MSFT on Stack Overflow
For example __init__.py imports
You may search for settings about additional import search resolution paths:
"python.analysis.extraPaths": [
"path1",
"path2",
],
Please have a try.
More information view Pylance Settings and Customization.
Similar to the accepted answer, but with GUI:
- press Ctrl+, to get into setting search
- write in the search bar extrapaths
- in the Python->Analysys: Extra Paths item - press Add Item
- Add your path (I used full path)
I currently have some test data in my code structure as I'm just testing things out. Is there a way to get pylance to ignore it as it's picking up 57 issues from a csv file of 50 lines of random data?
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"]