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

问题描述 投票:0回答:5

我在 Windows 上安装了 Git-Bash 和 conda,它提供了两个程序:

C:\Program Files\Git\git-bash.exe
C:\\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'.

我尝试了

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

知道如何解决这个问题吗?

可能的解决方法:

我担心这个问题,因为 VSCode 的集成终端使用它。我尝试使用

C:\Program Files\Git\git-bash.exe
作为集成终端,但它会打开一个新窗口,而不是 VSCode 中的“集成”。

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

如有任何帮助,我们将不胜感激。

anaconda git-bash
5个回答
7
投票

对我来说有两个问题:

  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 

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


0
投票

将这一行添加到 .bash_profile 解决了它:

. /c/Anaconda3/etc/profile.d/conda.sh

(有关更多信息,请参阅此相关问题的答案)


0
投票

仅对少数人有用:

conda init
需要在其后面有
bash
。因此,请使用
conda init bash
或任何其他 shell 名称。愚蠢的错误,但简单的修复。


0
投票

就我而言,只需在

conda init bash
中输入
git bash shell
即可解决问题。😉

© www.soinside.com 2019 - 2024. All rights reserved.