上下文:
- Windows 10+VS Code+WSL2
- WSL2使用Ubuntu 20.04,所有的开发环境都安装在发行版中
- 在发行版上,我使用pyenv创建虚拟环境
- 我的工作区有一个包含子项目文件夹 struct 的项目,我需要为一个特定子项目配置pylint
- 我使用的是python3.10,并且已经在虚拟环境中安装了pylint
- 虚拟环境文件夹低于
~/venvs/virtualenv
- 我已经在VS代码上 Select 了指向
~/venvs/virtualenv
个python二进制文件的python解释器
文件夹 struct :
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
我的问题是:
- 代码运行没有问题,但pylint在
A
中抱怨以下导入:from app.services import database
- 错误为
Unable to import 'app.services' pylint(import-error)
这些是我当前的settings.json文件(树上的B):
{
"editor.formatOnSaveMode": "file",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"python.formatting.provider": "autopep8",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
}
Question
我应该如何配置settings.json
才能让pylint识别导入?
除了代码运行之外,甚至连自动完成都在工作,这表明python解释器设置正确,因此问题似乎出在pylint上.