LoginSignup
7
13

More than 5 years have passed since last update.

VS code のPythonデバッグ機能でinput()を使う方法

Last updated at Posted at 2019-02-11

Visual studio codeのデバッグ機能が便利でよく使っているが、pythonでinput()処理のところでうまく機能しなかったので、そのための対処法。
多くの場合は以下の記事のようにデバッグのConfigurationを変えてexternal terminalを使えば解決するが、自分の環境ではexternal terminalを使える用にするまでに作業が必要だったのでそちらも記録する。
https://qiita.com/kawarayu/items/f736778cec04cb2ba3a9

ということで以下の2部構成。たぶん2番めはWindowsのみ必要になると思う。

  1. VS codeのデバッグexternal terminalの使用によりinput()を使えるようにする
  2. VS codeでexternal terminalを使える用にする方法

1. VS codeのデバッグでexternal terminalの使用によりinput()を使えるようにする

input()が含まれるPythonコードをデバッグするためにはDEBUGのconfiguration(写真)をPython: Terminal(External)に変更する
image.png
Python: Terminal(External)がない場合はAdd Configurationから足すことができる
image.png

参考
https://qiita.com/kawarayu/items/f736778cec04cb2ba3a9

2. VS codeでexternal terminalを使える用にする方法

問題

1に書いたとおり設定を変えることでExternal terminalは立ち上がったが入力ができなかった。
いろいろと調べたところ問題は以下の2つだった。
a. pythonw.exeを使用している
b. powershellを使用している

解決方法

a. pythonw.exeを使用している
pythonの実行ファイルとしてpythonw.exeを使用していたのでこれをpython.exeに変更する。
File→Preferences→Settingsから設定ウィンドウを開き"Python Path"を検索
pythonw.exeをpython.exeに変更
image.png

b. powershellを使用している
powershellを使用していることにより?conda activate baseが上手く実行されていなかった。
使うshellをcmd.exeにすることにより解決できた。
1と同様設定画面を開き"Shell"を検索。
cmd.exeに変更した。
image.png

参考
https://github.com/Microsoft/vscode/issues/60436


以上により無事にExternal Terminalで入力を行うことができるようになり、input()が含まれるコードのデバッグもできるようになった。

7
13
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
7
13