为什么我在导入模块时收到 Pylance 错误,就好像模块没有被识别一样?

时间:2021-04-23 15:35:39

标签: python import module

我在主脚本 (_test_.py) 所在的文件夹中有一个函数 (testfunc.py)。尝试将 testfunc 导入 _test_ 时,我收到 Pylance 错误。

enter image description here

请参阅以下脚本:

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

Pylance 的导入解析系统与 Jedi 不同。它会考虑您的工作区根目录,除非您指定,否则不会考虑任何其他目录根目录,它应该显示相对导入错误。

尝试将其添加到您的工作区 settings.json 文件中

"python.analysis.extraPaths": ["StackOverflow/"]
}

开发人员不认为它是 bug,因此您每次都必须设置单独的根。

相关问题