Open betatim opened 5 years ago
related/original issue https://github.com/jupyterhub/binderhub/issues/871
Activating the kernel
environment switches to the correct kernel as suggested in #871
So :+1: on activating that in the terminal by default, see my attempt below.
Digging into the issue
AFAICS the conda environment should be activated via file conda-activate.sh
: https://github.com/jupyter/repo2docker/blob/master/repo2docker/buildpacks/conda/activate-conda.sh#L17
But looking at the debug output of repo2docker locally, that file does not seem to be called. Should it be picked up by conda
automatically?
Could the problem be that conda activate
does not work?
jovyan@jupyter-nuest-2dpluc-5fmozambique-2difrz8msn:~$ conda activate /srv/conda/envs/notebook
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
When I run conda init bash
and start a new terminal, I can activate the different envs:
(notebook) jovyan@jupyter-nuest-2dpluc-5fmozambique-2difrz8msn:~$ conda env list
# conda environments:
#
base /srv/conda
kernel /srv/conda/envs/kernel
notebook * /srv/conda/envs/notebook
(notebook) jovyan@jupyter-nuest-2dpluc-5fmozambique-2difrz8msn:~$ conda activate /srv/conda/envs/kernel
(kernel) jovyan@jupyter-nuest-2dpluc-5fmozambique-2difrz8msn:~$ python --version
Python 2.7.15
(kernel) jovyan@jupyter-nuest-2dpluc-5fmozambique-2difrz8msn:~$
Note that in the listing, base
comes first.
Looking at the path in a repo where I encountered this issue (see https://discourse.jupyter.org/t/creating-environment-yml-for-python-2-via-binder/1609), I think there might be a bug in the third path element, which reads /srv/conda/condabin
. But still, the kernel is the first Python on the path, and /srv/conda/bin
also comes again later. The environment variable for the default env seems to be alright.
(kernel) jovyan@jupyter-nuest-2dpluc-5fmozambique-2difrz8msn:~$ echo $PATH
/home/jovyan/pcraster/bin:/srv/conda/envs/kernel/bin:/srv/conda/condabin:/home/jovyan/.local/bin:/home/jovyan/.local/bin:/srv/conda/envs/notebook/bin:/srv/conda/envs/kernel/bin:/srv/conda/bin:/srv/npm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
(kernel) jovyan@jupyter-nuest-2dpluc-5fmozambique-2difrz8msn:~$ echo $CONDA_DEFAULT_ENV
kernel
(kernel) jovyan@jupyter-nuest-2dpluc-5fmozambique-2difrz8msn:~$
Solution?
I have made the following changes, and the desired kernel is then active in the terminal rightaway (the echo
is of course not strictly needed but might help debugging in the future):
https://github.com/jupyter/repo2docker/compare/master...nuest:activate-conda
I also changed the docs to not use -n root
, so the default environment is exported, which is what users following those instructions probably want, right?
Happy to run tests (not done yet!) and potentially add a test if you think this goes in the right direction.
Bug description
In a repo with Python 2 selected via a
runtime.txt
the commandpython
launches Python 3.Expected behaviour
python
should launch version 2.How to reproduce
python
I think it is because of the order in which environments appear on the search path:
Not sure if this is a bug or merely "surprising behaviour" that needs documenting. Maybe we could write down somewhere why
/srv/conda/bin
does come before/srv/conda/envs/kernel/bin
to help people understand why it is this way.