Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Dec 22, 2022

Conversation

minrk
Copy link
Member

@minrk minrk commented Dec 14, 2022

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
Copy link
Member

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
Copy link
Member Author

minrk commented Dec 14, 2022

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
Copy link
Member

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.

jupyter_core/paths.py Outdated Show resolved Hide resolved
@jasongrout
Copy link
Member

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
Copy link
Member Author

minrk commented Dec 14, 2022

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

use CONDA_DEFAULT_ENV=base

if CONDA_PREFIX is set and CONDA_DEFAULT_ENV is not defined, assume it's the base env (not properly activated as an env)
@minrk
Copy link
Member Author

minrk commented Dec 14, 2022

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
Copy link
Contributor

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

@blink1073 blink1073 enabled auto-merge (squash) December 22, 2022 18:45
@blink1073 blink1073 merged commit 719c1c3 into jupyter:main Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants