[mini]conda env list 显示来自不同安装的 conda 的环境

[mini]conda env list is showing environments from a different installation of conda

我的机器上存在多个 conda 安装。我已将 $PATH 设置为安装在 /Users/steve/conda-hac

下的第二个
(base) 11:16:51/hercules-airflow3 $which conda
/Users/steve/conda-hac/bin/conda

让我们在那里创建一个环境:

$ conda create -n hac_conda

然而,当调用 conda env list 时,我们会看到之前由原始/第一个 conda 安装创建的环境:

(base) 11:17:14/hercules-airflow3 $conda env list
# conda environments:
#
                         /Users/steve/conda-hac
                         /Users/steve/conda-hac/envs/hac_tests
base                  *  /Users/steve/opt/miniconda3
air37                    /Users/steve/opt/miniconda3/envs/air37
airflow3                 /Users/steve/opt/miniconda3/envs/airflow3
hercl                    /Users/steve/opt/miniconda3/envs/hercl
juventas36               /Users/steve/opt/miniconda3/envs/juventas36

我检查了新环境 hac_tests 是否在预期的位置 - 是的:

3 $ls -lrta  /Users/steve/conda-hac/envs
total 0
-rw-r--r--   1 steve  staff    0 May  1 09:23 .conda_envs_dir_test
drwxr-xr-x   4 steve  staff  128 May  1 09:41 .
drwxr-xr-x  16 steve  staff  512 May  1 09:41 ..
drwxr-xr-x   8 steve  staff  256 May  1 09:41 hac_tests

再往下看,做了conda init bash之后conda还是other那个

注意我们正在执行的 conda (which conda) 是 /Users/steve/conda-hac/bin/conda 但从 conda init bash 返回的 conda

no change     /Users/steve/opt/miniconda3/condabin/conda`
$which conda
/Users/steve/conda-hac/bin/conda
(base) 11:48:15/hercules-airflow3 $conda init bash
no change     /Users/steve/opt/miniconda3/condabin/conda
no change     /Users/steve/opt/miniconda3/bin/conda
no change     /Users/steve/opt/miniconda3/bin/conda-env
no change     /Users/steve/opt/miniconda3/bin/activate
no change     /Users/steve/opt/miniconda3/bin/deactivate
no change     /Users/steve/opt/miniconda3/etc/profile.d/conda.sh
no change     /Users/steve/opt/miniconda3/etc/fish/conf.d/conda.fish
no change     /Users/steve/opt/miniconda3/shell/condabin/Conda.psm1
no change     /Users/steve/opt/miniconda3/shell/condabin/conda-hook.ps1
no change     /Users/steve/opt/miniconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change     /Users/steve/opt/miniconda3/etc/profile.d/conda.csh
no change     /Users/steve/.bash_profile

因此 conda init 上出现了奇怪的行为。如何让 /Users/steve/hac-conda 下的第二个 conda 安装环境正常工作?

可能来自 ~/.conda/environments.txt 文件。任何时候环境被激活,它都会记录在这里。由于这是在 user-level,任何安装都可以访问它。

问题似乎是由代码中的 conda_init(): it is hardcoded to a particular installation. Notice the /Users/steve/opt/miniconda3/bin/conda` 引起的:

conda_init() {
    # >>> conda initialize >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$('/Users/steve/opt/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
        eval "$__conda_setup"
    else
        if [ -f "/Users/steve/opt/miniconda3/etc/profile.d/conda.sh" ]; then
                 . "/Users/steve/opt/miniconda3/etc/profile.d/conda.sh"  # commented out by conda initialize
        fi
    fi
        export PATH="/Users/steve/opt/miniconda3/bin:$PATH"  # commented out by conda initialize
    unset __conda_setup
    # <<< conda initialize <<<
}

我将创建函数 conda_hac_init() 的第二个版本,它引用 /Users/steve/conda_hac

下的新安装