【问题标题】:Silence Conda Shell Warning沉默 Conda Shell 警告
【发布时间】:2020-01-22 09:55:00
【问题描述】:

当我在 Bash 脚本中激活 Conda 环境时:

#!/bin/bash
conda activate ./myenv
which python
python do_stuff.py

activate 行打印出长警告:

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

如何消除此警告?如果我运行它建议的conda init bash 命令,这会导致 Conda 默认为所有 Bash shell 激活我的环境,这绝对不是我想要的。这是 Conda 中的默认配置,在它破坏了我系统中各处的功能后,我明确将其关闭。我希望 Conda 的功能类似于 virtualenv,其中我有一个包含环境的文件夹,并且仅在特定应用程序需要时才激活它。在任何情况下,我都不希望为系统上任何地方运行的每个 Bash 实例激活 Conda 环境。

我不确定为什么它给了我一个 CommandNotFoundError,因为否则 Conda 会使用 Python 和其他特定环境资源的正确路径填充我的 Bash shell,并且其他一切都正常工作。

【问题讨论】:

    标签: python bash conda


    【解决方案1】:

    在您的脚本中添加以下代码。

    eval "$(command conda 'shell.bash' 'hook' 2> /dev/null)"
    

    这仅在脚本中初始化 conda。

    【讨论】:

    • 做到了。谢谢。
    【解决方案2】:

    初始化conda 后,默认情况下,它将在您打开的每个新shell 会话上自动激活基本环境。如果您想关闭此行为,只需运行一次:

    conda config --set auto_activate_base false
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-03
      • 2021-06-29
      • 2016-07-04
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多