An Jupyter plugin to enable the automatic detection of conda and virtualenv environments as kernels.
A Jupyter plugin to enable the automatic detection of environments as kernels.
This plugin looks in the directories you specify for installed environments which have Jupyter installed and lists them as kernels for Jupyter to find. This makes it easy to run one notebook instance and access kernels with access to different versions of Python or different modules seamlessly.
The plugin can be installed with:
pip install environment_kernels
To enable the plugin add the following line to your notebook config file:
c.NotebookApp.kernel_spec_manager_class = 'environment_kernels.EnvironmentKernelSpecManager'
To create a config file run:
jupyter notebook --generate-config
or run the notebook with the following argument:
The plugin works by getting a list of possible environments which might contain an ipython kernel.
There are multiple ways to find possible environments:
~/.conda/envsfor conda based environments and
~/.virtualenvs) for virtualenv based environments.
conda.config.envs_dirswill be imported and all subdirs of these dirs will be added to the list of possible environments.
CONDA_ENV_DIRvariable will be set and will be used to find the directory which contains the environments.
condaexecuteable is available, it will be queried for a list of environments.
Each possible environment will be searched for an
ipythonexecuteable and if found, a kernel entry will be added on the fly.
The ipython search pattern is on Linux and OS/X:
and on Windows:
The kernels will be named after the type (conda or virtualenv) and by the name of the environment directory (example: the kernel in conda environment
C:\miniconda\envs\testsgets the name
conda_tests). If there are multiple envs which would result in the same kernel name (e.g. when multiple base dirs are configured, which each contain an environment with the same name), only the first kernel will be used and this ommision will be mentioned in the notebook console log.
You can configure this behaviour in mutliple ways:
You can override the default base directories by setting the following config values:
You can also disable specific search paths:
The above disables both types of environments, so this will effectivly disable all environment kernels.
You can also disable only the conda call, which is expensive but the only reliable way on windows:
If you want to, you can also ignore environments with certain names:
Or you can specify a whitelist of "allowed" environments with:
The default lists all environmental kernels as
Environment (type_name). This can be cumbersome, as these kernels are usually sorted higher than other kernels.
You can change the display name via this config (you must include the placeholder
All config values can also be set on the commandline by using the config value as argument:
As an example: