20.VisualStudioCode設定

Python拡張機能のインストール


①サイドバーの[Extensions]を選択する。
②検索欄で「Python」を検索する。
③Microsoftが出しているPythonの拡張機能をインストールする。

Python拡張機能、ターミナル設定


①サイドバーの[Manage]から[Settings]を選択します。
②右上の「設定(UI)を開く」をクリックします。
③setting.jsonが開くので、以下の設定項目を編集します。
・python.condaPath:“[Anacondaインストールパス]\\anaconda3\\envs\\[環境名]”
・terminal.integrated.profiles.windows:“args”に「“/K”, “[Anacondaインストールパス]\\anaconda3\\Scripts\\activate.bat”, “[Anacondaインストールパス]\\anaconda3\\envs\\[環境名]“」
・terminal.integrated.defaultProfile.windows:”Command Prompt”
・python.defaultInterpreterPath: “[Anacondaインストールパス]\\anaconda3\\envs\\[環境名]\\python.exe”
・python.terminal.activateEnvironment: false
・code-runner.runInTerminal: true

上記設定をすると、以下のイメージになるかと思います。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"python.condaPath": "C:\\Users\\admin\\anaconda3\\envs\\py39",
"terminal.integrated.profiles.windows":{
 
         
    "PowerShell": {
        "source": "PowerShell",
        "icon": "terminal-powershell"
    },
    "Command Prompt": {
        "path": [
            "${env:windir}\\Sysnative\\cmd.exe",
            "${env:windir}\\System32\\cmd.exe"
        ],
        "args": [
        "/K ",
        "C:\\Users\\admin\\anaconda3\\Scripts\\activate.bat",
        "C:\\Users\\admin\\anaconda3\\envs\\py39"
    ],
        "icon": "terminal-cmd"
    },
    "Git Bash": {
        "source": "Git Bash"
    }
},
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"python.defaultInterpreterPath": "C:\\Users\\admin\\anaconda3\\envs\\py39\\python.exe",
"python.terminal.activateEnvironment": false,
"code-runner.runInTerminal": true

動作確認

①「ctrl」+「shift」+「`」を入力します。
②以下の通り、指定した環境変数でターミナルが開けば成功です。