Python

Python environment modules | Using the NCAR Package Library

Multiple versions of Python are available on the Cheyenne and Casper systems. Python installations are loaded via environment modules while packages can be loaded only using the NCAR Package Library (NPL).


Python environment modules

CISL recommends loading a Python environment module before invoking the python command. Invoking python without loading a module first will start an older system version (Python 2.7.13) that is used mostly for system scripting and other administrative tasks.

To load an environment module that will provide a Python 2 environment for you to use on Cheyenne, follow this example:

module load python/2.7.16

Alternatively, you can use Python 3 by running:

module load python/3.6.8

Using the NCAR Package Library

After loading the desired Python module, load all NCAR-provided Python packages at once by activating the NCAR Package Library virtual environment. Run the ncar_pylib script to activate the default version of the package library.

ncar_pylib

This utility can also be used to load older versions of the library, which are listed by the date of creation.

To list all versions of the package library:

ncar_pylib -l

To list the packages (and version numbers) that are included in a library version:

ncar_pylib -p 20190627

If a package that you want is not available in the current library, you can clone the library as described below and install the package for yourself using pip, or request a custom build by emailing cislhelp@ucar.edu.

When you are done and ready to exit the NPL virtual environment, run the command deactivate.

deactivate

Creating your own clone of the NCAR Package Library

Creating a personal clone of the package library in your GLADE space is useful if you want to add or update packages, or develop Python code while using NCAR-provided packages. Simply specify the clone option (-c) to ncar_pylib, select a version of the package library, and choose a destination path for the clone.

ncar_pylib -c 20190627 /glade/work/$USER/personal_clone_name

Then, use the standard virtual environment utility to activate your clone of the package library by sourcing it:

cd /glade/work/$USER/personal_clone_name/bin
source activate.csh (tcsh)
OR
source activate (bash)

You can then install or upgrade packages from the Python Package Index using the pip utility. For example, to install your own copy of the seaborn plotting library, you could run:

pip install seaborn

Creating Jupyter kernels from NPL versions

If you wish to use the NCAR Package Library inside of other Jupyter instances on Cheyenne (for example, inside a personal NPL clone or a conda environment), you can run the following command to produce a user-space kernel from a recent NPL version:

ncar_pylib --kernel 20190627

This kernel will be stored in your home directory and available in any instance of Jupyter that you load.