Reputation: 567
Context:
~/venvs/virtualenv
~/venvs/virtualenv
python binaryFolder structure:
main_project/
| .vscode/
| | settings.json <----- B
| sub_projects/
| | proj_1/
| | proj_2/
| | | src/
| | | | app/
| | | | | __init__.py
| | | | | api/
| | | | | | rest/
| | | | | | | __init__.py <--- A
| | | | | services/
| | | | | | __init__.py
| | | | | | database.py
The problem I have:
A
:
from app.services import database
Unable to import 'app.services' pylint(import-error)
These are my current settings.json file (B on the tree):
{
"editor.formatOnSaveMode": "file",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"python.formatting.provider": "autopep8",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
}
Question
How should I configure settings.json
to make pylint recognize the import?
Besides the code running, even the autocomplete is working, which shows that the python interpreter is properly set, so the problem seems to be pylint.
Upvotes: 2
Views: 813
Reputation: 9209
Vscode identification file is found with the workspace as the root directory. You can use the following methods to import method:
Use code from sub_projects.proj_2.src.app.services import database
Place a .env file at the root of your project which adds your source directory to PYTHONPATH:
PYTHONPATH=/sub_projects/proj_2/src/
Tips: You can add the following code to your settings.json, you can also change the file name here.
"python.envFile": "${workspaceFolder}/.env" // for example "python.envFile": "${workspaceFolder}/dev.env"
Upvotes: 1