【问题标题】:CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'CommandNotFoundError:您的 shell 未正确配置为使用“conda activate”
【发布时间】:2020-09-06 23:13:24
【问题描述】:

我正在尝试在 Google Colaboratory 上使用 conda 创建一个虚拟环境。 但是,我无法激活并出现以下错误。

    CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - 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

我尝试了两项改进。 我尝试了三个改进。 一种是将以下代码添加到~/.bashrc。

# >>> conda init >>>
__conda_setup="$(CONDA_REPORT_ERRORS=false '$HOME/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "$HOME/anaconda3/etc/profile.d/conda.sh" ]; then
        . "$HOME/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="$PATH:$HOME/anaconda3/bin"
    fi
fi
unset __conda_setup
# <<< conda init <<<

# ~~~~~~~~~~~~
conda create --name XXXXXX python=3.6 -y
conda activate XXXXXX 
# ~~~~~~~~~~~~

其次,我在 ~/.bashrc 中添加了以下代码

export PATH="$PYENV_ROOT/versions/anaconda3-2.5.0/bin/:$PATH"

第三,我在 ~/.bashrc 中添加了如下代码

. /opt/anaconda3/etc/profile.d/conda.sh
conda activate base

如果我尝试激活它们中的每一个,我会得到同样的错误。如果有人明白,请分享你的智慧。

谢谢

【问题讨论】:

  • 能否给出echo $SHELL的输出。我怀疑你的 shell 没有加载 ~/.bashrc - 也许它使用了不同的文件。另外我建议撤消~/.bashrc 中的所有修改,只使用conda init &lt;shell-name&gt; 来修改它——尤其是后面的那些弊大于利。

标签: python bash anaconda conda google-colaboratory


【解决方案1】:

答案在这里: https://github.com/conda/conda/issues/7980

source ~/anaconda3/etc/profile.d/conda.sh
conda activate my_env

也许您还使用了错误的 anaconda/miniconda 路径。 使用此命令产生的结果:

conda info | grep -i 'base environment'

:)

【讨论】:

  • 谢谢!为我工作。只需从第二个命令中首先获取 conda 路径。
  • 在上面的命令中,将 ~/anaconda3/ 替换为您的 miniconda / anaconda 安装路径。你可以通过运行找到它: conda info | grep -i '基础环境'
  • 但它似乎对我不起作用......!source /root/anaconda3/etc/profile.d/conda.sh !/root/anaconda3/bin/conda activate maskrcnn_benchmarkCommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. To initialize your shell, run $ conda init &lt;SHELL_NAME&gt; Currently supported shells are: - bash - 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'.如何解决它?((
  • 并且将export -f conda export -f __conda_activate export -f __conda_reactivate export -f __conda_hashr 添加到 /root/.bashrc 也不起作用
  • 这对我有用
【解决方案2】:

对我来说,最后一个答案here 有效。有点不方便,但总比没有好...所以,如果需要在conda环境中运行一些东西,我只是将!source &lt;path_to_activate_function&gt; my_env放在其他命令之前,如下:

!source ~/anaconda3/bin/activate vilbert-mt && conda env list

【讨论】:

    【解决方案3】:

    首先你必须运行

    conda init <your terminal type>
    

    例如:

    conda init bash
    

    你会得到类似的东西

    no change     /home/t/anaconda3/condabin/conda
    no change     /home/t/anaconda3/bin/conda
    no change     /home/t/anaconda3/bin/conda-env
    no change     /home/t/anaconda3/bin/activate
    no change     /home/t/anaconda3/bin/deactivate
    no change     /home/t/anaconda3/etc/profile.d/conda.sh
    no change     /home/t/anaconda3/etc/fish/conf.d/conda.fish
    no change     /home/t/anaconda3/shell/condabin/Conda.psm1
    no change     /home/t/anaconda3/shell/condabin/conda-hook.ps1
    no change     /home/t/anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh
    no change     /home/t/anaconda3/etc/profile.d/conda.csh
    no change     /home/t/.bashrc
    

    然后关闭当前终端窗口并再次打开(基本上重新打开) 现在,如果您输入 conda activate 它将起作用

    t@t:~$ conda activate
    (base) t@t:~$ ^C
    (base) t@t:~$ 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 2019-08-23
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      相关资源
      最近更新 更多