• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    Python
  • License
    BSD 2-Clause "Sim...
  • Created almost 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Jupyter plugin to enable the automatic detection of conda and virtualenv environments as kernels.

Automatic Environment Kernel Detection for Jupyter

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.

Installation

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:

--NotebookApp.kernel_spec_manager_class='environment_kernels.EnvironmentKernelSpecManager'

Search Directories for Environments

The plugin works by getting a list of possible environments which might contain an ipython kernel.

There are multiple ways to find possible environments:

  • All subdirs of the base directories (default: ~/.conda/envs for conda based environments and ~/.virtualenvs) for virtualenv based environments.
  • If the jupyter notebook is being run in the conda root environment conda.config.envs_dirs will be imported and all subdirs of these dirs will be added to the list of possible environments.
  • If the notebook server is run from inside a conda environment then the CONDA_ENV_DIR variable will be set and will be used to find the directory which contains the environments.
  • If a conda executeable is available, it will be queried for a list of environments.

Each possible environment will be searched for an ipython executeable and if found, a kernel entry will be added on the fly.

The ipython search pattern is on Linux and OS/X:

ENV_NAME/{bin|Scripts}/ipython

and on Windows:

ENV_NAME\{bin|Scripts}\ipython.exe

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\tests gets 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:

c.EnvironmentKernelSpecManager.virtualenv_env_dirs=['/opt/virtualenv/envs/']
c.EnvironmentKernelSpecManager.conda_env_dirs=['/opt/miniconda/envs/']

You can also disable specific search paths:

c.EnvironmentKernelSpecManager.find_conda_envs=False
c.EnvironmentKernelSpecManager.find_virtualenv_envs=False

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:

c.EnvironmentKernelSpecManager.use_conda_directly=False

Limiting Environments

If you want to, you can also ignore environments with certain names:

c.EnvironmentKernelSpecManager.blacklist_envs=['conda_testenv']

Or you can specify a whitelist of "allowed" environments with:

c.EnvironmentKernelSpecManager.whitelist_envs=['virtualenv_testenv']

Configuring the display name

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 {}!):

c.EnvironmentKernelSpecManager.display_name_template="~Env ({})"

Config via the commandline

All config values can also be set on the commandline by using the config value as argument:

As an example:

c.EnvironmentKernelSpecManager.blacklist_envs=['conda_testenv']

becomes

--EnvironmentKernelSpecManager.blacklist_envs="['conda_testenv']"

More Repositories

1

parfive

An asyncio based parallel file downloader for Python 3.7+
Python
47
star
2

mycroft-kodi

A Kodi search and playback skill for Mycroft AI
Python
18
star
3

octoprint-matrix-notifier-plugin

An octpront plugin for sending matrix notifications and snapshots.
Python
14
star
4

matrix-appservice-hangouts

A prototype Matrix<->Hangouts appservice written in Python 3.6 using asyncio.
Python
12
star
5

Thesis

Stuart's PhD Thesis
TeX
7
star
6

texfigure

A figure manager for PythonTeX
Python
6
star
7

PriMaRY-JOVE

A signal analysis program for the detection of Io events from Radio JOVE data.
Python
5
star
8

xmpp_chat

JavaScript
5
star
9

skill-twim

A benpa bot
Python
4
star
10

dot-spacemacs

My spacemacs config
Emacs Lisp
4
star
11

jupyter_reveal_offline_template

A repo to jump start your IPython + reveal.js presentation
JavaScript
4
star
12

sgespawner

A Sun Grid Engine Spawner plugin for Jupyter Hub
Python
4
star
13

giles

A Github bot to give you documentation links as commit statuses
3
star
14

sunspot_experiments

Python
3
star
15

skill-jitsi

An opsdroid skill for quickly sharing Jitsi call URLs
Python
3
star
16

pyHeliosphere

VOX file read and Mayavi plotting
C++
2
star
17

pyflct

A version of the "Fourier Local Correlation Tracking" (FLCT) code which might get some Python bindings at somepoint in the future.
C
2
star
18

matrix-notify-action

A simple Javascript action for sending build statuses to matrix
JavaScript
2
star
19

travis_wheels

A repository to create wheels for Travis!
Shell
2
star
20

scipy2014plotting

My entry for the "SciPy John Hunter Excellence in Plotting Contest"
Python
2
star
21

fido-indexing

A quick example / exercise about the new SunPy Fido API.
Jupyter Notebook
1
star
22

matrix_api_async

An asyncio wrapper for matrix_client.api
Python
1
star
23

astraX20-talk

JavaScript
1
star
24

skill-motw

Make Monster of the Week Skill checks easily
Python
1
star
25

cadair-nikola-theme

Cadair's Nikola theme
1
star
26

astropy-sphinx-theme

The Astopy project documentation theme
HTML
1
star
27

isbabymumfordhere

Is she here yet?
HTML
1
star
28

Thesis-Template

A PythonTeX Thesis template
TeX
1
star
29

sphinx-autoreload

A simple autorebuilding sphinx server
Python
1
star
30

org-mode-offline-reveal-template

A template for making reveal.js presentations with emacs org mode where all the required source files are not hosted on CDNs
Shell
1
star
31

aptgeo

A Python module for decoding APT data to coordinate aware data formats
Python
1
star
32

skill-github-linker

An opsdroid skill for linking to GitHub issues
Python
1
star
33

skill-intersphinx

Python
1
star