anaconda / nb_conda_kernels

Package for managing conda environment-based kernels inside of Jupyter
BSD 3-Clause "New" or "Revised" License
599 stars 70 forks source link

Change kernelspec install for root environment #183

Closed fcollonval closed 4 years ago

fcollonval commented 4 years ago

This raises the question of handling the root environment. If I go back to the use case, I activate the voila environment. I run the voilà command on a notebook that use the root environment. This means the code won't be executed in a properly activated root environment as it does not use the _RUNNERCOMMAND. So should I patch the code, to add the runner on the root environment kernelspec installation.

_Originally posted by @fcollonval in https://github.com/Anaconda-Platform/nb_conda_kernels/pull/172#issuecomment-688425933_

In the exported kernelspec there:

https://github.com/Anaconda-Platform/nb_conda_kernels/blob/e4481a1878623542a33e0e3adad4aba689bc808c/nb_conda_kernels/manager.py#L251-L252

RUNNER_COMMAND should be in all kernel specs as the sys.prefix using those kernel specifications may not be the one of the notebook/jupyterlab server.

Back to the use case, if I run voila on a notebook using the root environment kernel, the commands stack will be:

conda activate voila
voila notebook-using-root-env.ipynb

=> So the kernel will be executed with the root environment python. But the root environment will not be activated. So there may be inconsistency.

As proof from my computer, here is the content of $HOME/.local/share/jupyter/kernels/conda-root-py/kernel.json:

{"argv": ["/home/fcollonval/miniconda3/bin/python", "-m", "ipykernel_launcher", "-f", "{connection_file}"], "display_name": "Python [conda env:root] *", "language": "python", "metadata": {"conda_env_name": "root", "conda_env_path": "/home/fcollonval/miniconda3"}}

and the one for $HOME/.local/share/jupyter/kernels/conda-env-voila-py/kernel.json:

{"argv": ["python", "-m", "nb_conda_kernels.runner", "/home/fcollonval/miniconda3", "/home/fcollonval/miniconda3/envs/voila", "/home/fcollonval/miniconda3/envs/voila/bin/python", "-m", "ipykernel_launcher", "-f", "{connection_file}"], "display_name": "Python [conda env:voila]", "language": "python", "metadata": {"conda_env_name": "voila", "conda_env_path": "/home/fcollonval/miniconda3/envs/voila"}}

_Originally posted by @fcollonval in https://github.com/Anaconda-Platform/nb_conda_kernels/pull/172#issuecomment-689375089_

And actually, perhapsnb_conda_kernels.runner could also be modified not to re-activate if you're already in the correct environment.

_Originally posted by @mcg1969 in https://github.com/Anaconda-Platform/nb_conda_kernels/pull/172#issuecomment-689555206_