zl程序教程

您现在的位置是:首页 >  工具

当前栏目

VSCode:Import [包] could not be resolved in Pylance【Import “torch” could not be resolved Pylance】

VSCode in not be could import torch resolved
2023-09-27 14:20:40 时间

在VS Code中编写python文件时,import自定义module报错 “could not be resolved Pylance(reportMissingImports)”。

在这里插入图片描述
这是因为Pylance未找到自定义模块的地址,可以通过在settings.json文件中添加extraPaths来解决:

1.通过Shift+Ctrl+P打开设置栏,输入settings后找到Perference: Open Settings (JSON)
在这里插入图片描述
2.打开settings.json文件后添加下面的代码进去:

"python.analysis.extraPaths": [
    "./src",        // 自定义模块的相对路径,可多个,可绝对路径  
    "./modules"
]
</