The workflow that I try to setup is the following:
- have a dedicated conda environment with jupyterlab installed in it (no other jupyterlab installations in any other conda envs);
- for each new project create a separate conda environment with all the needed packages and register the ipykernel (which is also installed in the project’s env) for it.
There are two possibilities to do the latter.
One way is to just manually register ipykernel via:
conda install -n conda_env ipykernel
conda activate conda_env
ipython kernel install --user --name=my-conda-env-kernel
When I start jupyterlab from its dedicated environment, the project’s kernel gets visible in Jupyter Notebook’s kernel selection box. However, in this case, it doesn’t actually activate the project’s environment. There are some hacky workarounds with modifying system path manually (e.g., see jupyter notebook issue #4569), but it doesn’t really solve the main problem in general plus is really inconvenient.
An alternative way is to use nb_conda_kernels extension for registering kernels. It properly activates the project’s environment when its kernel is selected from the dropdown menu, but has a substantial flaw: when the picked kernel is being run, it cannot be interrupted. I have created a cross-issue in both jupyterlab and nb-conda-kernels repositories that describes steps to reproduce the problem:
- unable to interrupt cell execution with a kernel from an external environment · Issue #180 · Anaconda-Platform/nb_conda_kernels · GitHub
- unable to interrupt cell execution if jupyter uses kernel from a different environment · Issue #8388 · jupyterlab/jupyterlab · GitHub
Unfortunately, it remains unclear for me at which side the source of the problem sits. There is no feedback in these issues and it seems that no progress is made to provide a fix. I hoped that a new version of JupyertLab would resolve the issue, but it didn’t.
Maybe someone has already found the solution for making the described workflow work? Or maybe I’m just doing something that jupyterlab isn’t designed for? I know that possible workaround is just to have jupyterlab installed in each project’s env, but it leads to an overhead with keeping track of jupyterlab version in each env and updating it, etc. I’d prefer to maintain just a single jupyterlab installation and work with all my other conda environments from it.
I’d appreciate any help/feedback. Thanks!