Search code examples
condaenvironment

Failed measures to prevent conda from reverting to base environment


I installed Anaconda on my Windows 10 machine. The conda version is 4.9.0. The only non-base environment I have is py39 for Python 3.9

I followed this Stack Overflow answer in an attempt to keep py39 activated between sessions of the conda command window. I followed all three methods:

(i) conda config --set auto_activate_base false

(ii) Confirmed that c:\Users\User.Name\.condarc contains auto_activate_base: false

(iii) Created a user-level environment variable CONDA_AUTO_ACTIVATE_BASE=false in Windows 10 (not Bash/Linux)

After each one of these measures, I started the conda prompt window, activated the py39 environment, exitted, restarted the conda prompt window, and issued conda env list to confirm that the active environment had reverted back to the base environment (undesirably):

(base) C:\Users\User.Name>conda env list
# conda environments:
#
base                  *  C:\ProgramData\Anaconda3
py39                     C:\Users\User.Name\.conda\envs\py39

What am I doing wrong in trying to keep the py39 environment activated?


Solution

  • You are misunderstanding how environments work and what "auto activate base" means.

    When you start the conda prompt, then it really is just a powershell/cmd prompt that has additionally called activate on the base env. This is fixed in the startup of the prompt and only means that certain directories are added to environment variables like PATH and conda is set up to be able to run properly.

    When you call activate on your py39 env, then the environment variables are changed again such that your environment is found first. These changes, however are only active for the current session and not globally saved on your computer and there is no real way around it. When you start your prompt the enxt time, it will just do what it is set up to do. Set up the base env.

    What you can do however is simply modify the env that is started at startup. If you right-click the shortcut to your conda command prompt and select properties, you will see a field called Target that contains a line like this:

    %windir%\system32\cmd.exe "/K" C:\Users\Username\AppData\Local\mambaforge\Scripts\activate.bat C:\Users\Username\AppData\Local\mambaforge
    

    Exact locations might be different, but it should look something like this. The last directory is the env that gets activated, so we can change it to start the env that you want:

    %windir%\system32\cmd.exe "/K" C:\Users\Username\AppData\Local\mambaforge\Scripts\activate.bat C:\Users\Username\AppData\Local\mambaforge\envs\py39
    

    Make sure that you put the path that is correct on your system. You can find it by running these commands in your conda prompt

    activate py39
    echo %CONDA_PREFIX%