在 Git Bash 上安装 Anaconda 并尝试 conda activate 导致重复的 CommandNotFoundErrors

Dan*_*log 5 git-bash visual-studio-code anaconda

我最近更新了我的 Git Bash 和 Anaconda 安装,并且我正在尝试使用 Anaconda 从 VSCode 中运行 Git Bash。问题是,每当我从 VSCode 中打开集成终端时,终端都不会显示(基本)标签,并且当我运行时conda activate,它返回 CommandNotFoundError:

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'.
Run Code Online (Sandbox Code Playgroud)

我已按照说明操作conda init bash并重新启动了外壳程序,但它一直出现此错误。我看过其他几篇文章,但其中大部分已经过时,而其他文章没有有效的解决方案。当我不使用集成终端时,Anaconda 仍然可以在外部 Git Bash 上工作。任何帮助是极大的赞赏。

小智 8

当您运行conda init bash它时,它可能创建了一个~/.bash_profile文件。如果您希望 VS Code 的 git bash 终端了解它,请在 git bash 终端上执行以下操作:

echo '. ${HOME}/.bash_profile' >> ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

这会将 anaconda 添加到的任何命令.bash_profile也添加到.bashrc(为交互式非登录 shell 执行 - 这就是 VS Codes 获得的),而.bash_profile用于登录 shell(这是 git bash 每次打开新终端时运行的命令)。有更多关于另一个 SE 问题之间.bashrc和之间差异.bash_profile的信息。

注意:如果您有使用这些文件的经验,那么您可以从中复制所需的位.bash_profile,而不是获取其中可能包含的所有命令。

  • 非常感谢!为我工作! (2认同)

小智 1

您可以运行 source activate base 来启动并运行它,但无法使用 bash 终端在 VSCode 中运行 bash 脚本。如果有人发现请停止......

更多参考...

https://www.anaconda.com/conda-4-6-release/