conda init 在 Windows 上的 bash 中不起作用

Nee*_*eeX 10 git-bash anaconda

我在 Windows 上安装了 Git-Bash 和 conda,它提供了两个程序:C:\Program Files\Git\git-bash.exeC:\\Program Files\\Git\\bin\\bash.exe

后者C:\\Program Files\\Git\\bin\\bash.exe不能与 conda 正常工作。当我尝试时conda acitvate base,我收到一条消息:

Administrator@##### MINGW64 /bin
$ conda --version
conda 4.7.12

Administrator@##### MINGW64 /bin
$ conda activate base

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

Run Code Online (Sandbox Code Playgroud)

我尝试conda initconda init bash,然后关闭并重新打开bash.exe,但它仍然保持不变。

关于如何解决这个问题有什么想法吗?

可能的解决方法:

我担心这个问题,因为 VSCode 的集成终端使用它。我尝试使用C:\Program Files\Git\git-bash.exe集成终端,但它打开一个新窗口,而不是 VSCode 中的“集成”。

git-base.exe可以与 conda 配合使用,因此有关如何设置git-base.exe为 VSCode 集成终端的指南也是可以接受的。

任何帮助,将不胜感激。

hug*_*erg 8

对我来说有两个问题:

  1. conda init创建一个.bash_profile具有正确初始化的文件,但git-bash.exe加载.bashrc(感谢Auss的评论)
  2. 我的 bash 主目录不等于我的 Windows 主目录。Conda 创建C:\Users\<username>\.bash_profile和 bash 都需要~/.bashrc,但~/不等于C:\Users\<username>\

我的解决方案是

  • 从 VS Code 中的 git 终端运行code ~/.bashrc,以确保.bashrc在正确的位置创建
  • 复制内容C:\Users\<username>\.bash_profile并粘贴到打开的.bashrc
  • 重新打开 Git 终端


小智 5

将.bash_profile中的配置追加到.bashrc文件中

conda init bash
cat ~/.bash_profile >> ~/.bashrc 
Run Code Online (Sandbox Code Playgroud)

conda activate $ENVNAMEbash 重新启动后应该可以工作。