VSCODE anaconda使用時に「CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.」が発生した場合の対処法

VSCODE anaconda使用時に「CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.」が発生した場合の対処法

VSCODEで、anacondaのpython環境を使用時に「CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.」が発生した場合の対処法手順を記述してます。

環境

  • OS windows11 home
  • vscode 1.63.2

エラー全文

デバック実行時に「conda activate」で発生。

PS C:\python> conda activate test

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - cmd.exe
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

対処法

Windows PowerShellの設定を行う。

「anaconda powershell prompt」を起動します。

以下のコマンドを実行します。

>conda init powershell

次に、powershellを管理者として実行して以下のコマンドを実行します。

>Set-ExecutionPolicy RemoteSigned

実行ポリシーの変更
実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実行ポリシーを変更すると、about_Execution_Policies
のヘルプ トピック (https://go.microsoft.com/fwlink/?LinkID=135170)
で説明されているセキュリティ上の危険にさらされる可能性があります。実行ポリシーを変更しますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): y

これで、エラーは解消されました。