问题背景
在本地通过vscode连接autodl的服务器后,在服务器中使用conda activate name 命令激活虚拟环境时,报错:
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'.
现将解决步骤记录如下,bug并不复杂,方法亲测有效。最最重要的是,如果这篇记录稿对正在看文章的宝子们有所启发,还请点个小小的赞再走咯!!
解决方法
问题分析
CommandNotFoundError
表示当前的 shell 未正确配置以使用 conda activate
。要解决这个问题,我们只需要按照提示初始化shell 以支持 conda
命令就可以咯。
步骤
初始化你的 shell
如果使用的是bash
shell,可以按以下步骤操作:
-
初始化 shell:
conda init bash
-
关闭并重新打开 shell,或者运行以下命令以重新加载 shell 配置:
source ~/.bashrc
如果你不清楚自己的shell是哪一种,可以在命令行执行:
echo $SHELL
查看自己当前shell的类型
其他 shell
如果使用的是其他 shell,如 zsh
,可以运行:
conda init zsh
source ~/.zshrc
或者,如果是 fish
,则:
conda init fish
source ~/.config/fish/config.fish
验证
完成上述步骤后,再次尝试激活 conda
环境:
conda activate name
总结
通过上述步骤,我们就可以解决这个bug了——成功初始化你的 shell 以支持 conda
命令,并能够顺利激活 conda
环境。