【问题标题】:Where does conda get the default configuration values without a `.condarc`?没有 .condarc 的 conda 从哪里获得默认配置值?
【发布时间】:2022-02-04 01:47:34
【问题描述】:

我去寻找一些conda 设置。 (如果你必须知道,这与我的bash$PS1 搞乱有关——决定是使用conda 的配置还是环境变量。)为了找到设置,指令是查看@ 987654326@。为了找到.condarc,我被指示使用conda config --show-sources。我做到了,结果如下:

(base) [bballdave025@MYMACHINE ~]$ conda config --show-sources

(base) [bballdave025@MYMACHINE ~]$

即它是空白的。查看some conda documentation(以及它建议查看的路径)也没有产生任何.condarc。我在其他地方自己搜索过,但仍然没有。 没关系 - 我可以没有 .condarc 生活(我知道我可以通过 touch $HOME/.condarc 或通过使用 conda config --set changeps1 False 或任何 conda config --set <param-name> <value> 设置参数之一来创建一个)。

但是,当我查看配置参数(设置或默认值)时,我肯定看到了一些值。用于查看这些值的一些命令是 conda infoconda config --showconda config --describe。在我提出主要问题后,我将详细介绍这些命令。

这个问题几乎可以肯定是学术问题,但不知道却让我发疯:这些价值观来自世界上的什么地方?它们必须来自某个地方。我想它是某种文件,无论是本地的还是在线的某个地方,无论是基于文本的还是纯二进制的。我没有运气找到来源;显然,它不在任何.condarc 中,但它也不在我搜索过的其他任何地方。 conda 从哪里提取这些值?

本文的其余部分包含有关情况的详细信息以及我试图找到答案的尝试。真正的基础知识都在帖子的这一点之上。另一个快速说明:由于它们可能很有用,我的系统和conda info 上的信息在这篇文章的最后。


显示情况的命令

这里有一些命令显示缺少.condarc 并显示参数/设置的默认值的存在。

重复,

(base) [bballdave025@MYMACHINE ~]$ conda config --show-sources

什么都不返回 - 可能是一个空字符串,但我认为什么都没有。

.condarc 文件的其他搜索表明,in-conda 设置不可能来自任何名称类似于"*condarc*" 的文件。您可以查看查找"*condarc*" 文件部分了解详细信息。

这是我查看设置的方式。

(base) [bballdave025@MYMACHINE ~]$ conda config --show | head
add_anaconda_token: True
add_pip_as_python_dependency: True
aggressive_update_packages:
  - ca-certificates
  - certifi
  - openssl
allow_conda_downgrades: False
allow_cycles: True
allow_non_channel_urls: False
allow_softlinks: False

(base) [bballdave025@MYMACHINE ~]$ conda config --show | grep -i -C2 ps1
auto_update_conda: True
bld_path:
changeps1: True
channel_alias: https://conda.anaconda.org
channel_priority: flexible

其他命令似乎也验证了这一点:

(base) [bballdave025@MYMACHINE ~]$ conda info -a > tmpf && head -n 6 tmpf && rm tmpf

     active environment : base
    active env location : /home/bballdave025/anaconda3
            shell level : 1
       user config file : /home/bballdave025/.condarc
 populated config files :
(base) [bballdave025@MYMACHINE ~]$ conda config --describe | awk '/changeps1/' RS=  # Note the blank at the end
# # changeps1 (bool)
# #   When using activate, change the command prompt ($PS1) to include the
# #   activated environment.
# #
# changeps1: true

(base) [bballdave025@MYMACHINE ~]$ conda config --describe | awk '/env_prompt/' RS=  # Note the blank at the end
# # env_prompt (str)
# #   Template for prompt modification based on the active environment.
# #   Currently supported template variables are '{prefix}', '{name}', and
# #   '{default_env}'. '{prefix}' is the absolute path to the active
# #   environment. '{name}' is the basename of the active environment
# #   prefix. '{default_env}' holds the value of '{name}' if the active
# #   environment is a conda named environment ('-n' flag), or otherwise
# #   holds the value of '{prefix}'. Templating uses python's str.format()
# #   method.
# #
# env_prompt: '({default_env}) '

查找 `"*condarc*"` 文件

一个长输入,准备复制/粘贴。您可能只想直接进入输出部分。

find $HOME -type f -iname "*condarc*" -print0 | \
  xargs -I'{}' -0 \
    bash -c \
'orig="{}"; fname="${orig}"; '\
'dashes="----------------------------------"; '\
'echo "${dashes}"; echo "For file: '"'"'${fname}'"'"'"; '\
'echo "-----"; '\
'if ! grep -q "root_dir" "${fname}"; then '\
'  echo "   No '"'"'root_dir'"'"' in file; "'\
'"most likely invalid as a settings \`condarc\`"; '\
'  if grep -q proxy <(echo "${fname}"); then '\
'    echo "    There is a '"'"'proxy'"'"' in the filename, "'\
'"so it is not a huge surprise."; '\
'  fi; '\
'else '\
'  echo "   '"'"'root_dir'"'"' in file; "'\
'"could possibly be valid as a settings \`condarc\`"; '\
'fi; '\
'if grep -q changeps1 "${fname}" ; then '\
'  echo " From the file:"; '\
'  grep_str=$(grep changeps1 "${fname}"); '\
'  echo "${grep_str}"; '\
'  echo " From \`conda config --show | grep changeps1\`"; '\
'  condaconf_str=$(conda config --show | grep changeps1); '\
'  echo "${condaconf_str}"; '\
'    if [ "${grep_str}" = "${condaconf_str}" ]; then '\
'      echo "   The strings are equivalent, therefore the "'\
'"settings are equivalent."; '\
'      echo "   The in-conda settings could have come "'\
'"from this file."; '\
'    else '\
'      echo "   The strings - and therefore the settings - are "'\
'"not equivalent."; '\
'      echo "   The in-conda settings could not have come "'\
'"from this file."; '\
'      if grep -q test <(echo "${fname}"); then '\
'        echo "    There is a '"'"'test'"'"' in the file path, "'\
'"so it is not a huge surprise."; '\
'      fi; '\
'    fi; '\
'else '\
'  echo "   No '"'"'changeps1'"'"' found in file."; '\
'  echo "   The in-conda settings could not have come "'\
'"from this file."; '\
'fi; '\
'echo "${dashes}"; echo;';

显示没有 condarc 文件的长输出可能已用于当前的 in-conda 设置。

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.11.0-py39h06a4308_0/info/test/tests/condarc'
-----
   'root_dir' in file; could possibly be valid as a settings `condarc`
 From the file:
changeps1: False
 From `conda config --show | grep changeps1`
changeps1: True
   The strings - and therefore the settings - are not equivalent.
   The in-conda settings could not have come from this file.
    There is a 'test' in the file path, so it is not a huge surprise.
----------------------------------

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.11.0-py39h06a4308_0/info/test/tests/integration/proxy/condarc.proxybad'
-----
   No 'root_dir' in file; most likely invalid as a settings `condarc`
    There is a 'proxy' in the filename, so it is not a huge surprise.
   No 'changeps1' found in file.
   The in-conda settings could not have come from this file.
----------------------------------

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.11.0-py39h06a4308_0/info/test/tests/integration/proxy/condarc.proxygood'
-----
   No 'root_dir' in file; most likely invalid as a settings `condarc`
    There is a 'proxy' in the filename, so it is not a huge surprise.
   No 'changeps1' found in file.
   The in-conda settings could not have come from this file.
----------------------------------

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.10.3-py39h06a4308_0/info/test/tests/integration/proxy/condarc.proxybad'
-----
   No 'root_dir' in file; most likely invalid as a settings `condarc`
    There is a 'proxy' in the filename, so it is not a huge surprise.
   No 'changeps1' found in file.
   The in-conda settings could not have come from this file.
----------------------------------

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.10.3-py39h06a4308_0/info/test/tests/integration/proxy/condarc.proxygood'
-----
   No 'root_dir' in file; most likely invalid as a settings `condarc`
    There is a 'proxy' in the filename, so it is not a huge surprise.
   No 'changeps1' found in file.
   The in-conda settings could not have come from this file.
----------------------------------

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.10.3-py39h06a4308_0/info/test/tests/condarc'
-----
   'root_dir' in file; could possibly be valid as a settings `condarc`
 From the file:
changeps1: False
 From `conda config --show | grep changeps1`
changeps1: True
   The strings - and therefore the settings - are not equivalent.
   The in-conda settings could not have come from this file.
    There is a 'test' in the file path, so it is not a huge surprise.
----------------------------------

我正在运行系统范围的搜索(即来自 /,但不包括 /dev/ 之类的内容,这可能会弄乱这样的搜索)。基本上,除了find $HOME 将更改为sudo find / 并在末尾带有2&gt;/dev/null 之外,一切都将相同。我还将为changeps1 运行系统范围的grep。我怀疑我会找到任何东西,但值得一试。我将对我发现的内容进行编辑。

编辑:在我需要完成这些搜索之前,答案就已经出现了。


系统信息和 Conda 信息

            这是我的系统信息:

     (base) [bballdave025@MYMACHINE ~]$ uname -a
     Linux MYMACHINE 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 8 21:51:17 EST 
     2021 x86_64 x86_64 x86_64 GNU/Linux

            所以,我正在运行 RHEL 8 - Red Hat。

这是我的conda 信息:

(base) [bballdave025@MYMACHINE ~]$ conda info

     active environment : base
    active env location : /home/bballdave025/anaconda3
            shell level : 1
       user config file : /home/bballdave025/.condarc
 populated config files :
          conda version : 4.11.0
    conda-build version : 3.21.5
         python version : 3.9.7.final.0
       virtual packages : __linux=4.18.0=0
                          __glibc=2.28=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /home/bballdave025/anaconda3  (writable)
      conda av data dir : /home/bballdave025/anaconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/bballdave025/anaconda3/pkgs
                          /home/bballdave025/.conda/pkgs
       envs directories : /home/bballdave025/anaconda3/envs
                          /home/bballdave025/.conda/envs
               platform : linux-64
             user-agent : conda/4.11.0 requests/2.26.0 CPython/3.9.7 Linux/4.18.0-348.7.1.el8_5.x86_64 rhel/8.5 glibc/2.28
                UID:GID : 1001:1001
             netrc file : None
           offline mode : False

【问题讨论】:

  • 澄清一下,cat /home/bballdave025/.condarc 会返回任何东西吗?
  • 问得好,@jared_mamrot。不,它不会返回任何东西。输入:cat /home/bballdave025/.condarc;输出:cat: /home/bballdave025/.condarc: No such file or directory。要进一步检查,请输入:sudo stat /home/bballdave025/.condarc;输出:stat: cannot statx '/home/bballdave025/.condarc': No such file or directory。我实际上没有尝试过。我想,如果conda config --show-sources 没有拉起/home/bballdave025/.condarc,它一定不存在。如果cat 命令输出了所有参数,我会大笑的。谢谢。

标签: bash configuration conda default-value anaconda3


【解决方案1】:

如果没有 .condarc 源,Conda 将回退到 hardcoded in the conda.base.context.Context class 的值。这是一个相关的sn-p:

class Context(Configuration):

    add_pip_as_python_dependency = ParameterLoader(PrimitiveParameter(True))
    allow_conda_downgrades = ParameterLoader(PrimitiveParameter(False))
    # allow cyclical dependencies, or raise
    allow_cycles = ParameterLoader(PrimitiveParameter(True))
    allow_softlinks = ParameterLoader(PrimitiveParameter(False))
    auto_update_conda = ParameterLoader(PrimitiveParameter(True), aliases=('self_update',))
    auto_activate_base = ParameterLoader(PrimitiveParameter(True))
    auto_stack = ParameterLoader(PrimitiveParameter(0))
    notify_outdated_conda = ParameterLoader(PrimitiveParameter(True))
    clobber = ParameterLoader(PrimitiveParameter(False))
    changeps1 = ParameterLoader(PrimitiveParameter(True))
    env_prompt = ParameterLoader(PrimitiveParameter("({default_env}) "))
    # ...

【讨论】:

  • 很好的答案,@merv。我特别欣赏sn-p。你把我从一个 长期运行的 find / 管道到` fgrep -iIHn` 命令中救了出来。
猜你喜欢
  • 1970-01-01
  • 2017-01-29
  • 2015-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-27
  • 2019-05-19
相关资源
最近更新 更多