You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When VS Code is launched from an activated conda environment, prompt to select it #10668
Related to microsoft/vscode-docs#3481, if someone launches VS Code with a conda environment already activated, VS Code should detect that and then ask the user if they would like to make that environment their selected one.
You're right about the env variable. CONDA_SHLVL > 1 would indeed let you know if you are a "level" deeper than the base env, aka there is an environment activated. You actually could "Inception it" and go deeper as well. This can also be 0 as well which indicates that the conda command is available for the shell, but nothing is activated at all (even the base). Here is a little more information if you're curious.
As far as determining what env you are in, the CONDA_PREFIX env variable will show you that, or you could use conda info --json and check active_prefix, but the former would be the way to go.
Note that there is an open issue for this not working as it should on Windows: here which Kartik Raj (@karrtikr) is already aware of. The Anaconda team will make sure to get to that.
Activity
brettcannon commentedon Mar 31, 2020
From an activated Anaconda Prompt, the set environment variables appear to be (for an environment named "activatetest"):
karrtikr commentedon Nov 11, 2022
CONDA_SHLVLis the variable to check.In case of base environments only attempt to select it if auto activate base is set to false, see https://stackoverflow.com/questions/54429210/how-do-i-prevent-conda-from-activating-the-base-environment-by-default. Will likely have to check both
CONDA_AUTO_ACTIVATE_BASEandconda config --get auto_activate_base.LtDan33 commentedon Nov 24, 2022
You're right about the env variable.
CONDA_SHLVL > 1would indeed let you know if you are a "level" deeper than thebaseenv, aka there is an environment activated. You actually could "Inception it" and go deeper as well. This can also be0as well which indicates that the conda command is available for the shell, but nothing is activated at all (even the base). Here is a little more information if you're curious.As far as determining what env you are in, the
CONDA_PREFIXenv variable will show you that, or you could useconda info --jsonand checkactive_prefix, but the former would be the way to go.Note that there is an open issue for this not working as it should on Windows: here which Kartik Raj (@karrtikr) is already aware of. The Anaconda team will make sure to get to that.
karrtikr commentedon Jan 20, 2023
Upstream VSCode bug preventing autoselection at startup: microsoft/vscode#171827
Detect if VSCode is launched from an activated environment and select…
Merged PR posit-dev/positron-python#14: Merge upstream of vscode pyth…
Merged PR posit-dev/positron-python#14: Merge upstream of vscode pyth…