LoginSignup
73
80

More than 5 years have passed since last update.

VSCodeでPythonをデバッグする

Last updated at Posted at 2016-05-25

準備

インストール

Python公式ホームページ
上記のリンクからPythonをインストールする

拡張機能のインストール

Python
コマンドパレッド(Ctrl+P)を押して、下記のコマンドを実行する

コマンドパレッド
ext install python

デバッグ

  • launch.jsonを開く

A. コマンドパレッド(Ctrl+P)を押して、下記のコマンドを実行する

デバッグパレッド
> debug: Open launch.json

B. デバッグサイドバーのlaunch.jsonボタンを押す

image

  • 構成の選択に"Python"を入力する
    image

作成されたlaunch.jsonファイル

.vscode/launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "program": "${file}",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },
.... 省略
オプション 引数
"program": "${file}" 現在アクティブになっているファイルを開始します
"program": "${workspaceRoot}/file.py" ルートにあるfile.pyを開始します

launch.json を編集後、F5でデバッグを開始します
image

launch.jsonのオプション

※いい加減な翻訳なので注意してください

オプション 説明
program デバッグ対象のPythonファイルのパス
pythonPath Pythonインタプリタの絶対パス, 複数のバージョンのPythonを使い分けたい場合に使います
args 実行に渡される引数
stopOnEntry 有効な場合、デバッグ開始時に最初の行で止まります
externalConsole 有効な場合、コンソール/ターミナルウィンドウの表示にされます
debugOptions デバッグ用のオプション
env デバッグプロセス用のCustom環境変数を設定するために使います
73
80
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
73
80