Skip to content

When VS Code is launched from an activated conda environment, prompt to select it #10668

Description

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.

Activity

  1. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Mar 19, 2020
  2. brettcannon commented on Mar 31, 2020

    @brettcannon
    MemberAuthor

    From 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=2
    
  3. karrtikr commented on Nov 11, 2022

    @karrtikr

    CONDA_SHLVL is 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_BASE and conda config --get auto_activate_base.

  4. LtDan33 commented on Nov 24, 2022

    @LtDan33

    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.

  5. karrtikr commented on Jan 20, 2023

    @karrtikr

    Upstream VSCode bug preventing autoselection at startup: microsoft/vscode#171827

  6. locked as resolved and limited conversation to collaborators on Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-environmentsFeatures relating to handling interpreter environmentsfeature-requestRequest for new features or functionalityneeds PRReady to be worked onon-testplanAdded to test plan

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions