【问题】fish终端下激活conda环境报错:
bash
>> conda activate base
CondaError: Run 'conda init' before 'conda activate'
## 然而运行 conda init fish 仍旧无法解决
【解决】
参考:https://github.com/conda/conda/issues/11079
方法一:更新fish2至fish3版本
bash
## ubuntu
sudo apt-add-repository ppa:fish-shell/release-3
sudo apt update
sudo apt install fish
方法二:不更新fish,修改config.fish配置文件
将以下代码加至fish配置文件中,重启fish
bash
function conda --inherit-variable CONDA_EXE
if [ (count $argv) -lt 1 ]
eval $CONDA_EXE
else
set -l cmd $argv[1]
set -e argv[1]
switch $cmd
case activate deactivate
eval (eval $CONDA_EXE shell.fish $cmd $argv)
case install update upgrade remove uninstall
eval $CONDA_EXE $cmd $argv
and eval (eval $CONDA_EXE shell.fish reactivate)
case '*'
eval $CONDA_EXE $cmd $argv
end
end
end
环境名在fish shell左侧显示:
fish 配置文件(~/.config/fish/config.fish
)中加入:set -gx CONDA_LEFT_PROMPT 1