vscode基本使用
vscode基本使用
python环境配置
- 在插件栏目安装python插件
- 在当前目目录新建
.vscode\settings.json
配置python路径如下:
{
"python.pythonPath": "D:\\APP\\Anaconda3\\envs\\py37\\python.exe"
}
- 在当前目目录新建
.vscode\launch.json
配置python-debug如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
- 点击顶部的Debug–>start Debugging即可
c/c++环境配置
- 在插件栏目安装c/c++插件
- 在系统环境中配置环境变量
MinGW\\bin
- 在vscode中ctr+shift+P,选择
C/C++: select a configuration...
—>编辑配置json
,最终生成
- 在main.c中ctr+shift+P,选择
C/C++: Buid and Debug Activate file
—>gcc.exe 生成和调试文件
,最终生成
即此时就可以调试和运行c/c++程序,接下来通过配置debug方式避免每次都ctr+shift+P启动调试程序
(1)修改tasks.json
的 “label”: “gcc123”
{
"tasks": [
{
"type": "shell",
"label": "gcc123",
"command": "D:\\APP\\MinGW\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\APP\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
},
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "D:\\APP\\MinGW\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\APP\\MinGW\\bin"
}
}
],
"version": "2.0.0"
}
(2)点击左侧的Debug按钮 —》点击设置(open launch.json)。。。添加–》c/c++ (gdb) 启动
如下
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/src/main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\APP\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc123"
},
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
注意:
(1)"preLaunchTask": "gcc123"
和tasks.json
的 “label”: "gcc123"保持一致;
(2)“program”: "${workspaceFolder}/src/main.exe"路径修改为自己的
(3) “miDebuggerPath”: “D:\APP\MinGW\bin\gdb.exe”,路径修改为自己的
- debug的方式运行
通用的执行环境配置
- 在插件栏目安装插件
- 修改
settings.json
(这里主要修改python的运行"code-runner.executorMap":
)
{
"python.pythonPath": "D:\\APP\\Anaconda3\\envs\\py37\\python.exe",
"code-runner.runInTerminal": true,
"code-runner.saveFileBeforeRun": true,
"code-runner.executorMap": {
"python": "D:\\APP\\Anaconda3\\envs\\py37\\python.exe -u"
}
}
python的运行也可以先自己激活相应的虚拟环境,然后执行run-code