2

TL;DR

How do you stop the nb_conda_kernels automatic kernel detection in a Vertex AI User Managed Notebook instance?

Details

I am building Vertex AI User Managed Notebook instances from a Docker image. It all works great, except that the default Jupyter Lab installation seems to include the nb_conda_kernels extension. As far as I have been able to tell, the extension is the root of icon duplication in the Launcher, such that there will be two icons for each environment. There are various threads that have discussed this: here, here, here.

I am able to remove the unwanted icons by manually entering each environment and running jupyter kernelspec remove <name>. However, there must be a better way. I have tried uninstalling nb_conda_kernels, but the instance runs out of memory because of the complexity of the build (I think that's the cause, anyway). I have tried disabling the extension using python -m nb_conda_kernels.install --disable --prefix=$CONDA_PREFIX from the base environment, and also from within other environments, but it doesn't have the desired effect. I have also tried modifying the configuration file located at /opt/conda/etc/jupyter/jupyter_config.json, to include a CondaKernelSpecManager env_filter based on the example here. This does not seem to work either.

I am not attached to removing the extension, but I would like to remove its effects, or otherwise stop the duplication. In theory, disabling should do the trick. Could someone please tell me how to efficiently remove the nb_conda_kernels automatically-detected kernels from my icon list that appears in the Launcher? Ideally the solution would be something I could include either in my Docker file (unlikely, I suspect), or as a post-startup-script when using gcloud notebooks instances create (more likely, I suspect).

Thank you!

user6135514
  • 135
  • 9
  • I was able to replicate what you are describing. `I have tried disabling the extension using python -m nb_conda_kernels.install --disable --prefix=$CONDA_PREFIX` is the right way to do it, are you doing this from Dockerfile? – gogasca Nov 28 '22 at 08:37
  • I was running this from the Terminal within the Jupyter Lab environment. I have not tested it from the Dockerfile, as my workflow is generally to get the manual version working before I try to get the Docker image-based workflow to succeed. I just tested again by making a new conda python env, installing ipykernel into it, and then running `ipython kernel install --user --name=py39A --display-name python-3.9-A`. This generates the two icons, and running `python -m nb_conda_kernels.install --disable --prefix=$CONDA_PREFIX` from the Terminal has no effect. I will test from Dockerfile now. – user6135514 Nov 28 '22 at 10:38
  • Ok, thanks @gogasca. I'm confirming that adding `RUN python -m nb_conda_kernels.install --disable --prefix=$CONDA_PREFIX` to the end of the Dockerfile has the desired effect. I still need to do more testing but I think this should solve the issue. @gogasca, for my edification, could you please detail if/how this disabling could be run if a Notebook instance has already been created? – user6135514 Nov 28 '22 at 11:10
  • You may want to modify the container with `docker commit` to preserve state change. https://docs.docker.com.zh.xy2401.com/v17.12/engine/reference/commandline/commit/ Example: https://phoenixnap.com/kb/how-to-commit-changes-to-docker-image I haven't tried it myself, but that may work. – gogasca Nov 29 '22 at 21:56

1 Answers1

1

Per @gogasca's comment, including RUN python -m nb_conda_kernels.install --disable --prefix=$CONDA_PREFIX as the last line of the Dockerfile did work, even though it hadn't worked for me when testing interactively.

user6135514
  • 135
  • 9