This is a solution when you want to switch the environment variable PYTHONPATH for each of multiple folders in the same workspace (but you don't know how to switch).
"Import'xxx' could not be resolved Pyright (report Missing Imports)" warning from Pyright If the warning "Unable to import'xxx' pylint (import-error)" is displayed from pylint, you can change the search folder to be imported for each folder.
Also, even if there are import targets with the same name in multiple folders in the same workspace, proper syntax check and character completion will be effective.
I wanted to easily crush the import warning without dividing the workspace or using the virtual environment with venv, so I searched variously, but I could not find the topic of the same case, so I decided to make a trial and error. , Post as a memorandum.
src/
├── project1/
│ ├── .env (added this)
│ ├── .vscode/
│ │ └── settings.json (added this)
│ ├── project_root/
│ │ └── python_src/
│ │ ├── file1.py
│ │ └── file2.py
│ └── pyrightconfig.json (added this)
├── project2/
│ ├── .env (added this)
│ ├── .vscode/
│ │ └── settings.json (added this)
│ ├── project_root/
│ │ └── python_src/
│ │ ├── file1.py
│ │ └── file2.py
│ └── pyrightconfig.json (added this)
└── server_library/
└── python_src/
└── file3.py
Place "pyrightconfig.json" for each folder you want to switch PYTHONPATH directly under the workspace.
src/project1/pyrightconfig.json
{
"executionEnvironments": [
{
"root": "project_root",
"extraPaths": [
"project_root/python_src",
"../server_library/python_src"
]
}
]
}
json:src/project1/.vscode/settings.json
{
"python.envFile": "/(Path up to here)/src/project1/.env"
}
src/project1/.env
PYTHONPATH=/(Path up to here)/src/server_library/python_src:/(Path up to here)/src/project1/project_root/python_src
Recommended Posts