Creating a Python Kernel

Admin Prerequisite

Admin must enable conda for all users by creating a symlink. This will let users create their own virtual environment by using the conda create command.

1
ln -s /opt/conda/bin/conda /usr/local/bin/conda

User Instructions

Python

  1. Users can launch a terminal session with either JupyterHub or SSH connections. Launch a bash session.
1
bash
  1. Users then can create a virtual environment in the following way. Note that specifying ipykernel package will make the user easily create jupyter kernels from that environment. Also users can create virtual environments with various python versions(3.6 ~ 3.9). Activate the environment. If any warnings occur, read the warning and do the recommended procedure. Most of the time you will need to refresh your shell with bash.
1
2
3
4
5
6
7
8
# create environemnt
conda create -n NAME_OF_VIRTUAL_ENV python=3.8 ipykernel

# refresh your shell
bash

# activate environemnt
conda activate NAME_OF_VIRTUAL_ENV
  1. Install packages via pip.
1
2
3
4
5
# directly
pip install PACKAGE_NAME

# requirements.txt
pip install -r YOUR_REQUIREMENTS.txt
  1. Add the virtual environment as a kernel. This will be only available to each user.
1
python -m ipykernel install --user --name NAME_OF_VIRTUAL_ENV --display-name "[displayKenrelName]"

R

  1. Launch a bash session via JupyterHub or SSH.
1
bash
  1. Users then can create a virtual environment in the following way.
1
2
3
4
5
6
7
8
# create environemnt
conda create -n NAME_OF_VIRTUAL_ENV r-essentials r-base r-irkernel

# refresh your shell
bash

# activate environemnt
conda activate NAME_OF_VIRTUAL_ENV
  1. Install packages via install.packages().
1
2
# directly
Rscript -e 'install.packages(c("dplyr"))'
  1. Add the virtual environment as a kernel. This will be only available to each user.
1
Rscript -e "IRkernel::installspec(name='myRkernel', displayname='My R Kernel')"

Removing Kernels

To remove kernels use the jupyter command in terminal.

View your current kernel list with the following command from a bash terminal.

1
jupyter kernelspec list

Remove kernel with the following command.

1
jupyter kernelspec remove KERNELNAME