WestCoastProjects
WestCoastProjects

Reputation: 63162

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

Multiple conda installations exist on my machine. I have set the $PATH to the second one installed under /Users/steve/conda-hac

(base) 11:16:51/hercules-airflow3 $which conda
/Users/steve/conda-hac/bin/conda

Let's create an environment there:

$ conda create -n hac_conda

However when invoking conda env list we see the environments previously created by the original / first conda installation:

(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

I checked to see if the new environment hac_tests were in the expected place - and yes it is:

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

Looking further, after doing conda init bash, the conda is still the other one.

Notice the conda we're executing (which conda) is /Users/steve/conda-hac/bin/conda but the conda returned from conda init bash is

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

So there is strange behavior on the conda init. How can I get the environment working properly for the second conda installation under /Users/steve/hac-conda ?

Upvotes: 3

Views: 1033

Answers (2)

WestCoastProjects
WestCoastProjects

Reputation: 63162

The problem appears to be due to the conda_init(): it is hardcoded to a particular installation. Notice the /Users/steve/opt/miniconda3/bin/conda` within the code:

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 <<<
}

I will be creating a second version of the function conda_hac_init() that references the new installation under /Users/steve/conda_hac

Upvotes: 1

merv
merv

Reputation: 76950

Possibly coming from the ~/.conda/environments.txt file. Any time an environment gets activated, it is logged here. Since this is at the user-level, any installation will have access to it.

Upvotes: 5

Related Questions