[英]Python Intellisense VSCode Wrong Autocomplete Imports & PyLint wrong impor-error warning
My current app structure is:我当前的应用程序结构是:
backend
-- api
|-- migrations
|-- app
| -- main
| -- routes.py
| -- modules
| -- Mod1
| -- helper.py
| -- controller.py
| -- Mod2
| -- helper.py
| -- controller.py
|-- venv
|-- application.py
My settings (saved in .vscode
within the backend
folder):我的设置(保存在
backend
文件夹中的.vscode
中):
"python.pythonPath": "${workspaceFolder}/api/venv/bin/python3",
"python.envFile": "${workspaceFolder}/api/.env",
"python.venvPath": "${workspaceFolder}/api/venv/bin/python3",
If I try to import a module, I would normally do from app.modules.mod1 import controller
.如果我尝试导入模块,我通常会执行
from app.modules.mod1 import controller
。 But VSCode Intellisense keeps correcting me to from api.app.modules...
- which doesn't work (Flask gives me an Import Error).但是 VSCode Intellisense 不断将我纠正为
from api.app.modules...
- 这不起作用(Flask 给我一个导入错误)。
Pylint also keeps telling me that my imports are wrong, even though my app runs fine. Pylint 也一直告诉我我的导入是错误的,即使我的应用程序运行良好。 I adjusted the
pylint-path
as per this answer, but still gives me the same error.我根据这个答案调整了
pylint-path
,但仍然给我同样的错误。
I also lost the ability to "navigate" my code - I can't hold Cmd and click a function. Any ideas on what I might me doing wrong?我也失去了“导航”我的代码的能力——我不能按住 Cmd 并单击 function。关于我可能做错了什么有什么想法吗? It's a tremendous lost in productivity to miss the autocomplete and function links...
错过自动完成和 function 链接是生产力的巨大损失......
For further reference, the developers on Python Language (VSCode) answered my question, I needed to add:为了进一步参考,Python 语言 (VSCode) 的开发人员回答了我的问题,我需要添加:
{
"python.autoComplete.extraPaths": ["./api"]
}
I found myself in the same boat and I needed two settings to make this work:我发现自己在同一条船上,我需要两个设置来完成这项工作:
{
"python.autoComplete.extraPaths": ["./api"],
"python.analysis.extraPaths": ["./api"]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.