---
lang: ja-jp
breaks: true
---
# Python を Visual Studio Code で実行する。 2021-07-21
## 参考
> 【Python講座】第4回 仮想環境の作成と「VS Code」の設定【独り言】
> https://youtu.be/YTl4CBxw9ik
{%youtube YTl4CBxw9ik %}
> Variables Reference
> https://code.visualstudio.com/docs/editor/variables-reference
## インタプリタの選択(※実行するPythonを選択)
2023-05-11現在のスクリーンショット
※インタプリタの選択ボタンが右側に移動しているようだ。

:::warning
過去のスクリーンショット

:::
## インタプリタ選択後に `Ctrl+@` でターミナルを開くと、選択された アナコンダ または Python 仮想環境が有効化された状態となる

## Python仮想環境を使用する場合の `launch.json`
```json=
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"python": "${workspaceFolder}/venv/Scripts/python.exe"
}
]
}
```
## Anaconda仮想環境を使用する場合の `launch.json`
```json=
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"python": "${env:USERPROFILE}\\anaconda3\\envs\\AI\\python.exe"
}
]
}
```
## conda の設定
```shell=
> where conda
C:\Users\xxxx\anaconda3\Library\bin\conda.bat
C:\Users\xxxx\anaconda3\Scripts\conda.exe
C:\Users\xxxx\anaconda3\condabin\conda.bat
```
#### `settings.json`
```json=
{
・・・
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"python.condaPath": "${env:USERPROFILE}\\anaconda3\\condabin\\conda.bat"
・・・
}
```
###### tags: `Python` `Visual Studio Code`