Utilizing Anaconda Environments in JupyterHub

Anaconda allows users to create and manage Python versions and packages.
Anaconda allows users to create and manage Python versions and packages.

Anaconda is a completely free enterprise-ready Python distribution for large-scale data processing, predictive analytics, and scientific computing. It includes over 195 of the most popular Python packages for science, math, engineering, and data analysis. It also offers the ability to easily create custom environments by mixing and matching different versions of Python and other packages into isolated environments that individual users are free to create. Anaconda includes the `conda` package and environment manager to make managing these environments straightforward.

Several users have asked if it is possible to use Anaconda environments within Jupyter Notebooks through HCC's JupyterHub instance. Not only is it possible, its relatively easy to do when you follow these steps.

1. Stop any running Jupyter Notebooks and ensure you are logged out of the JupyterHub instance.

- To log out, click the Control Panel button located in the top right corner. Then click the "Stop My Server" Button to terminate the Jupyter server. Last, click the logout button in the top right corner.

2. Log into the command-line environment using an SSH client or within the Sandstone portal.

3. Load the Anaconda environment you wish to make accessible with the command `source activate myenv` where `myenv` is replaced with the name of the target environment.

- For information on creating a new environment, please see the documentation on Using Anaconda Python.

4. Install the ipykernal package into the active environment with the command `conda install ipykernel`.

5. Install the kernel specification with the command 'python -m ipykernel install --user --name myenv --display-name "Python (myenv)"'

6. Add any other desired packages and deactivate the environment with `source deactivate`.

The previous steps will be sufficient to make the conda environment available to local Jupyter Notebooks.

To make your conda environments accessible from SLURM Notebooks, enter the following commands:
mkdir -p $WORK/.jupyter
mv ~/.local/share/jupyter/kernels $WORK/.jupyter
ln -s $WORK/.jupyter/kernels ~/.local/share/jupyter/kernels

Note: This last step only needs to be done once. Any future created environments will automatically be accessible from SLURM notebooks once this is done.

To check that your environment has been created correctly, login to JupyterHub and select a Jupyter Notebook job profile. Create a new notebook using the environment by selecting the correct entry in the `New` drop-down menu in the top right corner.

If you encounter difficulty or errors in this process, please contact us at hcc-support@unl.edu for assistance.

More details at: https://hcc-docs.unl.edu/display/HCCDOC/Using+Anaconda+Python