问题描述
我正在使用以下组件运行 Vscode:
版本:1.51.1(用户设置)提交:e5a624b788d92b8d34d1392e4c4d9789406efe8f日期:2020-11-10T23:34:32.027Z电子:9.3.3铬:83.0.4103.122Node.js:12.14.1V8:8.3.110.13-electron.0操作系统:Windows_NT x64 10.0.20270皮兰斯 2.6
我有以下目录结构:
srcm1.py.vscode设置.json库m2.py.vscode设置.json
在开发 Python 代码时,我在这个环境中使用了几个短绒.Mypy
没有问题,但 pylance
无法解析导入.
当 pylance
失败时,我试图从 m1.py
导入模块 m2.py
.我src
目录下的settings.json
文件是:
{python.autoComplete.extraPaths":[*.lib"]}
谁能看到如何解决这个问题?
如果你的 VSCode 工作区文件夹是 src
文件夹的父文件夹,Pylance
抱怨是正常的因为默认情况下,项目的根目录是您的工作区文件夹.你可以看到,如果我 import src.lib.m2
Pylance
不会抱怨,但如果我使用 lib.m2
就会:>
由于您在运行代码时没有运行时错误,我会说您在运行 m1.py
时位于 src
文件夹内.
如果我的假设不正确,您需要添加更多详细信息(代码示例,您如何运行 m1.py
文件)
I am running Vscode with the following components:
Version: 1.51.1 (user setup)
Commit: e5a624b788d92b8d34d1392e4c4d9789406efe8f
Date: 2020-11-10T23:34:32.027Z
Electron: 9.3.3
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Windows_NT x64 10.0.20270
Pylance 2.6
I have the following directory structure:
src
m1.py
.vscode
settings.json
lib
m2.py
.vscode
settings.json
I use several linters with this environment when developing Python code. Mypy
does not have a problem but pylance
is unable to resolve imports.
I am trying to import the module m2.py
from m1.py
when pylance
fails. My settings.json
file under the src
directory is:
{
"python.autoComplete.extraPaths": [
"*.lib"
]
}
Can anyone see how to resolve this problem?
If your VSCode workspace folder is the parent of the src
folder it is normal to have Pylance
complain because by default the root of your project is your workspace folder. You can see that if I import src.lib.m2
Pylance
doesn't complain but it does if I use lib.m2
:
Since you don't have a runtime error when running your code I would say you are inside the src
folder when you run m1.py
.
If my assumptions are not true, you'll need to add more details (code sample, how do you run the m1.py
file)
这篇关于Pylance 的 VSCode 设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!