How Can We Help?
< All Topics
Print

Working with Software Packages and Libraries within a CyberGISX Jupyter Notebook

Available Libraries and Packages

Libraries are listed under the CyberGIS-Jupyter Kernels category. You can view what is available for a particular Kernel version.


Adding Libraries or Packages that are not included in CyberGISX

Persistently change the module(s) used

Unfortunately the !<command> syntax won’t work because the command executes in its own subshell. To dynamically and persistently change modules in a Python notebook, Lmod provides a “module” Python command which you can load with:

import sys, os
sys.path.insert(0, os.path.join(os.environ['MODULESHOME'], "init"))
from env_modules_python import module

and then you just pass in the string you want to execute with the module command like

module("load", "TauDEM/5.3.9-dev-foss-2019b")

changes made this way should persist throughout the notebook.

Using locally installed Python packages

You can install packages locally with pip:

!pip install --user <package>

You can add your local site packages to the environment with the following lines:

import sys, site
sys.path.append(site.getusersitepackages())

then simply import the necessary packages. This command essentially means “I want to append my user site packages to my system’s path.”

Using locally installed R packages

First, make a folder to house your R packages. Your default folder area is in ~/work so if you make a folder there called myrlibs. You can install packages to this location from the notebook with:

install.packages("shiny", lib="~/work/myrlibs")

Packages installed anywhere in ~/work will be persistent, meaning they should continue to exist even after your notebook is shut down.

To use your locally installed packages, put your local package location in the path:

.libPaths(c('~/myrlibs',.libPaths()))

Once this is done, you should be able to simply load your library:

library('shiny')
Table of Contents