将vscode内置的终端改为bash终端后出现的conda activate报错问题

将vscode内置的终端改为bash终端

这里简述一下vscode中最新配置bash终端的方式,我看网上的方法配置的方式都是旧版的了,vscode已经提示不要再使用了。我们打开vscode的配置文件,

如今的配置方式应该是

 "terminal.integrated.profiles.windows": {
     "bash": { //bash是自己取的别名
     "path": "D:\\Git\\bin\\bash.exe",
     }
 },
 "terminal.integrated.defaultProfile.windows": "bash" // 可以自定义默认终端

conda activate报错问题

由于conda activate命令会导致CommandNotFoundError

本质原因是在bash终端中只认source activate命令。它不认识conda activate,但它们的工作原理是一样的。

在将vscode内置的终端改为bash终端后,我出现了一下报错

 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'.

解决办法

用户目录下(即~目录)配置一个bash的配置文件.bashrc

 echo "source activate" >> ~/.bashrc

这相当于bash启动时使用source activate这个命令

它会使你每次打开bash都执行source activate,这样就解决了报错问题

image-20211117194250563

注意切换成base环境后头上会有个(base)

如果不想用base环境则使用命令conda deactivate反激活环境

 conda deactivate

猜你喜欢

转载自blog.csdn.net/Joey9898/article/details/121386102