Custom Kernels

Action

To use Custom Kernels for your Own Python Environment (anaconda), follow the instructions below.

Instructions

Install Anaconda

First, if you haven't already, download and install anaconda or miniconda 

# CD to your lab directory, or use your home directory, then wget https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh # Once downloaded, bash Anaconda3-2021.11-Linux-x86_64.sh

Then, run the bash script and follow the prompts. By default, anaconda will install to your home directory, but it is recommended to install to your shared lab directory due to a larger quota. When you see the PREFIX prompt, please specify the correct path to your lab directory (/network/rit/lab/[xxxx])

Now, create a kernel from the jupyterhub terminal, using your ipython install

/path/to/anaconda3/bin/ipython kernel install --user --name myconda # Note that you can make the name anything you choose

Note, that this will install the kernel to a hidden file in your home directory,

~/.local/share/jupyter/kernels/myconda 

Need to specify environment variables?

Use vim or emacs to edit 

and add the "env" key, which provides a dictionary of environment variables for jupyerhub to initialize with. We will add a "PATH" key, and "LD_LIBRARY_PATH" key. Note you must change /path/to/conda to your conda install location. It is not necessary to change anything else. 

Refresh the page, open a new launcher and your new kernel will appear

Launch the new kernel, and check to make sure it installed properly

Open up a notebook, or console as the new kernel and run

You should see the path to your conda environment appear. Now, any packages you install to your conda will be accessible in the notebook. 

Installing a conda package from the notebook/console

To install a package from the notebook or console, use the example below, which is installing a package called 'statsmodels'

Installing a custom kernel via venv

You can also install a custom kernel via venv in case you are unable to use conda.

Log in and create a venv without pip in a folder you can access.

Source it:

Install pip by curling the get-pip.py script and piping it to python.

Deactivate

Reactivate (this step is required for OL7, may not be needed for OL8 and later)

Install ipykernel via pip, with the prefix matching the destination of where you want your kernel to be stored. --name will be a unique name for your kernel, --display-name is what the user interface in jupyter notebook will display for you, so pick something descriptive!

Your kernel should now be available in jupyter notebook. Wait 1-2 minutes and refresh the notebook page, then in the top right you can pick your kernel from a drop-menu.

From here you can use your kernel as you want. If you have issues, email askIT@albany.edu for assistance.

 

 

 

Â