nprogram’s blog

気ままに、プログラミングのトピックについて書いていきます

VSCodeでPythonをデバッグしたい

はじめに

Windows環境で、Visual Studio CodeでPythonをデバッグしたいと思います。

環境

  • Windows 10 (version 1809)
  • Python version : 3.7.1
  • IDE : Visual Studio Code
    • Version : 1.31.1

方法

  1. Visual Studio Codeをインストールします
  2. Pythonをインストールします
  3. Visual Studio Code上で、Ctrl + Shift + Pでコマンドパレットを開きます
  4. タスク : タスクの構成を選択
  5. 更に一覧が出てくるので「Others 任意の外部コマンドを実行する例」を選択
  6. tasks.jsonファイルを以下のように修正

tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "python",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "command": "python",
            "args": [
                "${file}"
            ],
            "presentation": {
                "echo": false,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "problemMatcher": []
        }
    ]
}

最後に、F5で実行します

f:id:nprogram:20190305000928p:plain

参考文献