CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘.

问题描述

  • 使用 conda activate 激活虚拟环境时报错:
conda activate virtual_env
  • 提示内容
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - 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'.

原因

  • 提示内容已经给出原因,当前使用的 shell 没有配置好 conda activate,需要运行 conda init 初始化 shell
  • 一般使用 zsh shell 时,首次激活 conda 虚拟环境时会遇到

解决方法

  • 方法一:根据提示运行 conda init ,重启 shell 后即可正常使用 conda activate 激活虚拟环境的指令
# 如使用 zsh,则
conda init zsh
# 如果使用 bash,则
conda init bash
  • 方法二:首次激活 conda 虚拟环境,可用 source activate 激活(如下),以后就可以正常使用 conda activate 激活虚拟环境了
# 首次使用 source activate 命令激活虚拟环境 my_conda_virutal_environment
source activate my_conda_virutal_environment
# 退出虚拟环境
conda deactivate
# 以后使用 conda activate 命令激活虚拟环境
conda activate my_conda_virutal_environment

猜你喜欢

转载自blog.csdn.net/sdnuwjw/article/details/112448792