jupyter / jupyter_core

Core Jupyter functionality
https://jupyter-core.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
195 stars 181 forks source link

Don't treat the conda root env as an env #324

Closed minrk closed 1 year ago

minrk commented 1 year ago

For the purposes of 'preferring env config', I don't think it makes sense to treat the conda root prefix as an environment. This is quite likely to be a shared, not writable installation, and it would be more consistent to be treated like any other base Python install.

related: #318

jasongrout commented 1 year ago

If I download the anaconda or miniconda distribution, install it in my user directory, and fire it up, the default is to be in the CONDA_ROOT environment, right? Isn't that one of the most common cases for using anaconda?

minrk commented 1 year ago

Yes, it's the most common and I think it shouldn't get treated like an env. That's why I think it's an important bug to fix.

A base anaconda install is more equivalent to a homebrew-installed Python than a virtualenv, in my mind.

jasongrout commented 1 year ago

Yes, it's the most common and I think it shouldn't get treated like an env. That's why I think it's an important bug to fix.

Okay, I agree. On the plus side, that makes the behavior for venv and conda consistent, i.e., the base install is not considered a preferred path.

jasongrout commented 1 year ago

I just installed a fresh install of miniconda on macos, and tried to see what CONDA_ROOT would give me.

Here is the base environment:

$ python -c "import os; print(*(f'{k}:{v}\n' for k,v in os.environ.items() if k[:4]=='COND'))"
CONDA_SHLVL:1
 CONDA_EXE:/[my user directory]/opt/miniconda3/bin/conda
 CONDA_PYTHON_EXE:/[my user directory]/opt/miniconda3/bin/python
 CONDA_PREFIX:/[my user directory]/opt/miniconda3
 CONDA_DEFAULT_ENV:base
 CONDA_PROMPT_MODIFIER:(base) 

and here is what a small test environment gives me

$ python -c "import os; print(*(f'{k}:{v}\n' for k,v in os.environ.items() if k[:4]=='COND'))"
CONDA_SHLVL:2
 CONDA_EXE:/[my user directory]/opt/miniconda3/bin/conda
 CONDA_PYTHON_EXE:/[my user directory]/opt/miniconda3/bin/python
 CONDA_PREFIX:/[my user directory]/opt/miniconda3/envs/newenv
 CONDA_DEFAULT_ENV:newenv
 CONDA_PROMPT_MODIFIER:(newenv) 
 CONDA_PREFIX_1:/[my user directory]/opt/miniconda3

Where is CONDA_ROOT?

minrk commented 1 year ago

huh, I must have confused my own environment variables for conda's! I'll look again at detecting the root env the right way.

minrk commented 1 year ago

I think CONDA_ROOT may be years old and no longer used (it's in my bashrc). I cleared all conda envs and started fresh:

unset $(env | grep CONDA | cut -d= -f1)
source $PREFIX/etc/profile.d/conda.sh
conda activate base
env | grep CONDA
CONDA_EXE=/Users/minrk/conda/bin/conda
CONDA_PREFIX=/Users/minrk/conda
CONDA_PROMPT_MODIFIER=(base)
_CE_CONDA=
CONDA_SHLVL=1
CONDA_PYTHON_EXE=/Users/minrk/conda/bin/python
CONDA_DEFAULT_ENV=base

So the two logical choices are:

  1. CONDA_DEFAULT_ENV=base (base is a reserved name, you can't create another env with this name)
  2. resolve prefix from CONDA_EXE, which is platform-dependent

I elected to consider CONDA_DEFAULT_ENV being unset to mean we're not in an env, because that should mean that conda activate has not been called. I could go either way on that, but I went with lacking confidence that we are in an env should mean we don't opt-in to env behavior, rather than the other way around.

blink1073 commented 1 year ago

I'm happy to try out this and #323 and wait for feedback.