【问题标题】:conda init doesn't work in bash on Windowsconda init 在 Windows 上的 bash 中不起作用
【发布时间】:2020-02-11 18:02:57
【问题描述】:

我在我的 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'.

我尝试了conda initconda init bash,然后关闭并重新打开bash.exe,但还是一样。

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

可能的解决方法:

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

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

任何帮助将不胜感激。

【问题讨论】:

  • 谢谢@Simba。但实际上我的路径中有conda。我打电话给conda --version,bash 成功显示了 conda 的信息。
  • 我遇到了同样的问题。我将我的 .bash_profile 重命名为 .bashrc 并且它起作用了
  • @Auss 这对我有用,你能解释一下为什么吗?
  • @Auss 除非您知道这些文件已经包含什么,否则最好将 .bash_profile 复制到 .bashrc 而不是重命名它。这些是来自不同场合的文件,将来可能会导致交互式登录或类似问题出现问题

标签: anaconda git-bash


【解决方案1】:

对我来说有两个问题:

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

我的解决办法是

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

【讨论】:

    【解决方案2】:

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

    conda init bash
    cat ~/.bash_profile >> ~/.bashrc 
    

    conda activate $ENVNAME 应该在 bash 重启后工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多