Repository navigation
When VS Code is launched from an activated conda environment, prompt to select it #10668
Description
Activity
- addedfeature-requestRequest for new features or functionalityRequest for new features or functionalitytriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
on Mar 19, 2020 - ghost removedtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
on Mar 19, 2020 - addedarea-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environments
on Mar 19, 2020 brettcannon commented
on Mar 31, 2020 MemberAuthorMore actionsFrom an activated Anaconda Prompt, the set environment variables appear to be (for an environment named "activatetest"):
CONDA_DEFAULT_ENV=activatetest CONDA_EXE=C:\Users\brcan\AppData\Local\Continuum\miniconda3\Scripts\conda.exe CONDA_PREFIX=C:\Users\brcan\AppData\Local\Continuum\miniconda3\envs\activatetest CONDA_PREFIX_1=C:\Users\brcan\AppData\Local\Continuum\miniconda3 CONDA_PROMPT_MODIFIER=(activatetest) CONDA_PYTHON_EXE=C:\Users\brcan\AppData\Local\Continuum\miniconda3\python.exe CONDA_SHLVL=2CONDA_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.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.
Reacted by Kartik RajUpstream VSCode bug preventing autoselection at startup: microsoft/vscode#171827
- added a commit that references this issue
on Jan 23, 2023 - locked as resolved and limited conversation to collaborators
on Feb 24, 2023
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.