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'.
你遇到的这个错误是因为 PowerShell 没有被 conda 正确初始化,导致无法识别conda activate命令,这是在 VSCode 中使用 conda 环境时非常常见的问题。
步骤 1:在 PowerShell 中初始化 conda

首先,以管理员身份打开 PowerShell(这一步很重要,否则可能权限不足),然后执行以下命令:

powershell

# 初始化PowerShell,让conda配置生效
conda init powershell

执行完成后,必须关闭当前所有的 PowerShell 窗口和 VSCode,然后重新打开。

步骤 2:(可选)解决 PowerShell 执行策略限制

如果初始化后仍然报错,大概率是 PowerShell 的执行策略限制导致 conda 的配置脚本无法运行,执行以下命令修改策略:

powershell

# 以管理员身份运行,设置执行策略为RemoteSigned
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

执行后会提示确认,输入 Y 并回车即可。

步骤 3:在 VSCode 中验证并使用 conda 环境

重新打开 VSCode 后,按以下方式操作:

  1. 打开终端(Ctrl+`),确认终端类型是 PowerShell
  2. 直接输入激活命令:

    powershell

    conda activate BMS_tools
    
    如果终端左侧出现 (BMS_tools) 前缀,说明环境激活成功。

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐