Jupyter Sessions

Jupyter Notebooks are an excellent resource for interactive development and data analysis using Python, R, and other languages. Jupyter notebooks can contain live code, equations, visualizations, and explanatory text, which provide an integrated environment to use, learn, and teach interactive data analysis. Users can obtain quick access to Jupyter sessions using Open OnDemand and easily launch a JupyterLab interface. The JupyterLab interface is a fantastic tool that provides a highly customizable graphical user interface (GUI) that allows users to easily navigate multiple Jupyter Notebooks and the CURC filesystem.

Find packages available to you within a notebook

The Python 3 (idp) notebook kernels have many preinstalled packages. To query a list of available packages from a python notebook, you can use the following nomenclature:

from pip._internal import main as pipmain 
pipmain(['freeze'])

If the packages you need are not available, you can create your own custom environment and Jupyter kernel.

Creating your own custom Jupyter kernel

Anaconda is an open-source software that provides access to python and R distributions, and it includes the conda package manager to easily install software and packages. Software and associated Jupyter kernels other than python and R can also be installed using conda. The following steps describe how to create your own custom Anaconda environments and associated Jupyter kernels for use within a Jupyter Session.

Follow these steps from a terminal session. You can get a new terminal session directly from Jupyter using New-> Terminal.

1. Configure your conda settings

Follow our Anaconda documentation for steps on configuring your conda settings via ~.condarc.

2. Activate the CURC Anaconda environment

[johndoe@c3cpu-a5-u15-4 ~]$ module load anaconda

You will know that you have properly activated the environment because you should see (base) in front of your prompt. For example,

(base) [johndoe@c3cpu-a5-u15-4 ~]$

3. Create a new custom environment

Follow our Anaconda documentation for steps on creating your own custom conda environment.

4. Activate your new environment

(base) [johndoe@c3cpu-a5-u15-4 ~]$ conda activate mycustomenv
Note: We assume here that you’ve named your environment mycustomenv; please replace mycustomenv with whatever name you gave your environment!

5. Create your own custom kernel, which will enable you to use this environment in your Jupyter Session

For a python kernel

(mycustomenv) [johndoe@c3cpu-a5-u15-4 ~]$ conda install -y ipykernel
(mycustomenv) [johndoe@c3cpu-a5-u15-4 ~]$ python -m ipykernel install --user --name mycustomenv --display-name mycustomenv
  • The first command will install the ipykernel package if not installed already.
  • The second command will create a python kernel with the name mycustomenv with the Jupyter display name mycustomenv (note: the name and display-name are not required to match the environment name – call them anything you want). By specifying the --user flag, the kernel will be installed in /home/$USER/.local/share/jupyter/kernels (a directory that is in the default JUPYTER_PATH) and will ensure your new kernel is available to you the next time you launch a Jupyter Session.

For an R kernel

(mycustomenv) [johndoe@c3cpu-a5-u15-4 ~]$ conda install -y r-irkernel
(mycustomenv) [johndoe@c3cpu-a5-u15-4 ~]$ R
> IRkernel::installspec(name = 'mycustomenv', displayname = 'mycustomenv')
  • The first command will install the irkernel package if not installed already.
  • The second command will start R. The third command, executed from within R, will create an R kernel with the name mycustomenv with the Jupyter display name mycustomenv (note: that the name and display-name are not required to match the environment name – call them anything you want). The kernel will be installed in /home/$USER/.local/share/jupyter/kernels (a directory that is in the default JUPYTER_PATH) and will ensure your new kernel is available to you the next time you launch a Jupyter Session.

Notes:

  • If you have already installed your own version of Anaconda or Miniconda, it is possible to create Jupyter kernels for your preexisting environments by following Step 4 above from within the active environment.
  • If you need to use custom kernels that are in a location other than /home/$USER/.local/share/jupyter (for example, if your research team has a group installation of Anaconda environments located in /pl/active/<some_env>), you can create a file in your home directory named ~/.jupyterrc containing the following line:
export JUPYTER_PATH=/pl/active/<some_env>/share/jupyter

If you need assistance creating or installing environments or Jupyter kernels, contact us at rc-help@colorado.edu.

Troubleshooting

  • If you are a CSU or ACCESS user and are having trouble with packages that employ PERL (due to the @ symbol), visit our documentation on setting up a user variable that links to alternate paths without the @ symbol in CSU and XSEDE/ACCESS usernames