1

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?

user2153235
  • 388
  • 1
  • 11
  • 1
    Done. I'm working through FlyingTeller's answer, it may solve the problem, so the relevance of these details might be overtaken by events. – user2153235 Jun 21 '23 at 19:53

1 Answers1

2

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%
FlyingTeller
  • 17,638
  • 3
  • 38
  • 53
  • Thanks, FlyingTeller! Based on [this explanation] of `auto_activate_base`, I will reverse the measures that I decribed in my posted question. Based on your description, I found a Start Menu shortcut `C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)\Anaconda Prompt (Anaconda3)`. The "Target" field contains `%windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3`. The "Start in" field contains `%HOMEPATH%`. – user2153235 Jun 21 '23 at 20:23
  • I copied that shortcut to `C:\Users\User.Name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)\Anaconda Prompt (Anaconda3) py39` and modified the "Target" to `%windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:%HOMEPATH%\.conda\envs\py39`. This created a corresponding shortcut in the Start Menu, which starts the conds prompt with the *py39* environment. – user2153235 Jun 21 '23 at 20:23
  • I removed the Windows 10 environment variable `CONDA_AUTO_ACTIVATE_BASE` and removed the `auto_activate_base` from `.condarc`. I temporarily had `auto_activate_base` set to true, but it occurred to me that I don't know if that was present in a virgin environment. So I simply removed it. – user2153235 Jun 21 '23 at 20:52