一、概述
经常遇到这个问题,特记录解决方法,供后续遇到同样问题时查阅。
二、解决方法
在当前根目录创建.vscode文件夹,文件夹里创建launch.json和setting.json两个文件。
1、设置launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"python": "/home/xxxx/anaconda3/envs/torch/bin/python",
"program": "${file}",
"cwd": "${workspaceRoot}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
2、设置setting.json
{
"python.pythonPath": "/home/xxxx/anaconda3/envs/torch/bin/python",
}
3、配置解释器环境
(1)点击界面左下角齿轮【管理】-> Command Palette 【命令面板】;
(2)输入 Python:Select Interpreter;
(3)选择指定的conda虚拟环境。
大功告成!