Using a Kernel Based on a Conda Environment

Hi folks,
I wonder how to force my jupyter notebook to use a specific kernel based on a conda environment. For instance, I created a kernel using a specific requirements.yml file (which lists all the dependencies for this environment). Then I exported the environment to jupyter. This environment is supposed to use tensorflow 1.13. The version of tensorflow installed in my over all anaconda installation is version 2. However, when I check the version of tensorflow from my new notebook (using the kernal based on the environment that I created), it shows it to be 2.11. I wonder why is that? Any help would be really appreciated.

There are a few tools to manage this.

nb_conda_kernels exists, but hasn’t seen any attention from maintainers for a long time.

gator was originally a fork of the above, and has seen more development recently. It also conflates the concern of building and managing environments, a la nb_conda (also abandoned), and uses mamba, which is usually an order of magnitude faster than conda at solving and generally better at downloading as well.

However, the simplest mechanism is something akin to the docs, with the last example being the most self-contained, (and therefore scriptable):

/path/to/kernel/env/bin/python -m ipykernel install \
  --prefix /path/to/jupyter/env \
  --name python-my-env \
  --display-name "Python 3 (other-env)"
/path/to/kernel/env/bin/python -m jupyter kernelspec list

This avoids some of the complications in the other examples, such as intermediate /tmp files, the --user environment (which makes all kinds of things unpredictable).