夜owl

困到睡不着
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

vscode技巧笔记3-调试编译

Posted on 2024-05-29 22:38  夜owl  阅读(38)  评论(0编辑  收藏  举报

1. 概述

vscode作为一个编辑器,同样也是开发工具,本文介绍运行调试环境

2. 通用配置

vscode 支持多种语言,这里介绍下通用配置,c和python(我自己用的)作为章节介绍

2.1. 运行相关界面

2.1.1. 语言解释器(language mode)和解释器

vscode会自动识别文件的后缀名然后进入对应的语言模式,如果是编程语言还会自动选择系统中配置好的语言的解释器
会显示在右下角或者左下角
Alt text

2.1.2. 运行

可以通过右键文件直接运行

2.1.3. 调试

进入调试(F5),

在代码左边数字行数点击可以添加断点进行单步调试

2.2. 调试(debug)

在侧边栏的run and debug 可以进入调试工作区,在工作区可以设置调试器,每次运行都可以生成一个终端或者虚拟环境(instance)
Alt text

2.2.1. launch.json

launch.json 是用于配置 Visual Studio Code 中调试器的文件,它通常与特定的项目和语言相关。在项目中的.vscoe创建一个名为 launch.json 的文件,或者全局保存为 User 配置文件,并根据自己需求进行配置。

具体调试配置文件是通过配置launch.json来配置的,点击在上面的图片的齿轮可以打开该文件

2.3. 插件

python

  • ms-python.vscode-pylance
  • donjayamanne.python-environment-manager
  • ms-python.python

3. python环境配置

3.1. 预置条件

3.1.1. python

安装Python的教程网上有很多。直接到官网下载安装就行。

Welcome to Python.org

3.1.2. 插件

见上面

3.2. 配置解释器

使用命令Python: Select Interpreter或者点击右下方的配置解释器进入选择python解释器,pc中有多个版本的要特别注意,不同的版本安装的packages 不同,很多模块没有识别,可能就是版本不对,也可以自己选定路径
Alt text

3.3. 工作环境配置

3.3.1. 安装模块管理

在侧边栏的python可以进行环境配置,主要是模块管理
Alt text

3.4. 运行配置

3.4.1. 调试(debug)

通过插件可以自动添加python配置,
Alt text

参考配置

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: 当前文件",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    },
    {
      "name": "Python: 模块",
      "type": "python",
      "request": "launch",
      "module": "enter.module.name.here",
      "console": "integratedTerminal"
    },
    {
      "name": "Python: 外部终端",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    }
  ]
}