【发布时间】:2020-04-01 22:21:37
【问题描述】:
我用 VSCode 打开了一个目录(在 WSL Ubuntu 上),结构如下:
.
├── .vscode
│ ├── launch.json
│ └── settings.json
├── src
│ └── polls
│ ├── aiohttpdemo_polls
│ │ ├── db.py
│ │ ├── main.py
│ │ ├── routes.py
│ │ ├── settings.py
│ │ └── views.py
│ ├── config
│ │ └── polls.yaml
│ └── init_db.py
└── ve_websocket
在导入与调用它的目录位于同一目录中的文件时,我收到警告消息unresolved import ...。示例:routes.py
from views import index
def setup_routes(app):
app.router.add_get("/", index)
我收到unresolved import 'views' Python(unresolved-import)。因此,index 函数的 IntelliSense 不起作用。
但是 IntelliSense 建议使用这种表示法:
from polls.aiohttpdemo_polls.views import index
现在,index 函数已被 IntelliSense 识别,并且没有出现警告消息,但是在保存文件时,我现在收到此错误消息 Unable to import 'polls.aiohttpdemo_polls.views' pylint(import-error)。
所以我不能运行这个脚本:
[polls]$ python init_db.py
我的settings.json 文件有这样的配置:
"python.pythonPath": "ve_websocket/bin/python3.8",
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "pylint",
【问题讨论】:
标签: python visual-studio-code module warnings python-import