'Why is VS Code calling the wrong virtual environment as base?

I have some conda virtual environments in a server I SSH into in a daily basis. Logging in from the terminal and listing the environments gives me the following:

(base) [rgr6291@klc0201 ~]$ conda env list
# conda environments:
#
fomc                     /home/rgr6291/.conda/envs/fomc
r_conda                  /home/rgr6291/.conda/envs/r_conda
rfe_paper                /home/rgr6291/.conda/envs/rfe_paper
base                  *  /software/python-anaconda3/2019.10

So I have base and three virtual environments. I usually edit code on the server using Visual Studio Code and the Remote SSH extension. VS Code recognizes all these environments when I am prompted to select the Python interpreter:

enter image description here

It turns out that starting a terminal window from VS Code leads to different behavior whether I am on the fomc environment or not.

If I select, say, the rfe_paper environment and start a new terminal from withing VS Code, I get the following automatic output:

source activate rfe_paper
(base) [rgr6291@klc0201 HF_FOMC]$ source activate rfe_paper
(rfe_paper) [rgr6291@klc0201 HF_FOMC]$ 

It starts up the terminal and then activates the desired environment. However, the same procedure from the fomc environment leads to something different:

source /home/rgr6291/.conda/envs/fomc/bin/activate
(base) [rgr6291@klc0201 HF_FOMC]$ source /home/rgr6291/.conda/envs/fomc/bin/activate
(base) [rgr6291@klc0201 HF_FOMC]$ conda activate fomc

(base) [rgr6291@klc0201 HF_FOMC]$ conda env list
# conda environments:
#
base                  *  /home/rgr6291/.conda/envs/fomc
r_conda                  /home/rgr6291/.conda/envs/r_conda
rfe_paper                /home/rgr6291/.conda/envs/rfe_paper

Notice that there is an extra source call in the beginning. And somehow VS Code is misled and believes the fomc environment is the base one.

  1. What might be causing this?
  2. How to fix this?

It was working fine yesterday but it seems broken today. The only difference is that I exported the installed packages in fomc to an yml file this morning. I don't know how that would affect behavior.

By the way, let me report the following as well. This is the content of ~/.conda/envs/fomc/bin/activate:

#!/bin/sh
_CONDA_ROOT="/home/rgr6291/.conda/envs/fomc"
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
\. "$_CONDA_ROOT/etc/profile.d/conda.sh" || return $?
conda activate "$@"

I think CONDA_ROOT is wrong, but I have no idea of what it should actually be.

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source