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

电玩女神 2023-09-29 15:22 79阅读 0赞

在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文件后添加下面的代码进去:

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

发表评论

表情:
评论列表 (有 0 条评论,79人围观)

还没有评论,来说两句吧...

相关阅读