Difference between revisions of "Jupyterhub"

From CAC Wiki
Jump to: navigation, search
(Created page with "== Using JupyterHub and JupyterLab == JupyterLab is the next-generation of Jupyter notebooks. It is setup in a multi-user fashion using the JupyterHub web application. Loggin...")
 
 
(6 intermediate revisions by 2 users not shown)
Line 21: Line 21:
 
JupyterHub is a web interface that sends commands to Python process running in the background. This Python process, called a kernel, is what is actually executing your code. We’ve setup JupyterHub with a few common kernels for common Python configurations and R. If you want to add a kernel (from say a custom Python environment or other programming language), follow the instructions for your kernel from here.
 
JupyterHub is a web interface that sends commands to Python process running in the background. This Python process, called a kernel, is what is actually executing your code. We’ve setup JupyterHub with a few common kernels for common Python configurations and R. If you want to add a kernel (from say a custom Python environment or other programming language), follow the instructions for your kernel from here.
  
For simple cases (you just want to add a new Python kernel for a custom Python environment), follow the process here:
+
Note: conda is not recommended as it may lead to conflicts with the cvmfs software stack that is part of both CAC and the Digital Research Alliance of Canada. We strongly recommend using virtualenvironment instead.
  
# create a new conda environment called "kerneltest" and add it to Jupyterhub
+
== Installing Python packages from Digital Research Alliance of Canada wheelhouse ==
conda create -n kerneltest
+
 
source activate kerneltest
+
The default python kernel on the launcher does not have access to Digital Research Alliance of Canada wheelhouse https://docs.alliancecan.ca/wiki/Available_Python_wheels. You can use the Frontenac cluster and/or the <code>Terminal</code> on the launcher window of JupyterHub to install required packages in a virtual environment and make it visible on your JupyterHub.
conda install pandas ipykernel  # demo environment with pandas and ipykernel
+
 
# you need to name the kernel or else it will hide the default python3 one!!!
+
<pre>
python -m ipykernel install --user --name kerneltest
+
[user@caclogin03 ~]$ module load python/3.11
# login to jupyterhub, restart your server through the control panel
+
[user@caclogin03 ~]$ virtualenv my_env_py311
# kernel is now available through jupyterhub
+
[user@caclogin03 ~]$ source my_env_py311/bin/activate
 +
(my_env_py311) [user@caclogin03 ~]$ pip install numpy --no-index #include any required packages
 +
(my_env_py311) [user@caclogin03 ~]$ pip install ipykernel --no-index
 +
(my_env_py311) [user@caclogin03 ~]$ python -m ipykernel install --user --name my_env_py311 --display-name "my_env_py311_JH"
 +
[user@caclogin03 ~]$ deactivate
 +
</pre>
 +
 
 +
Restart your JupyterHub session to view and use your virtual environment named <code>my_env_py311_JH</code>.
 +
 
 +
[[File:JupyterHub_ipykernel.png|frameless|upright=3.45]]
 +
   
 +
(Under Construction)

Latest revision as of 17:16, 17 April 2024

Using JupyterHub and JupyterLab

JupyterLab is the next-generation of Jupyter notebooks. It is setup in a multi-user fashion using the JupyterHub web application. Logging in

To log in, just go to JupyterHub link. You will need to enter your username and password to log in.

To log out, select Hub, then Log Out from the JupyterHub interface.

The JupyterHub interface

JupyterHub provides two ways of working: using Jupyter Notebooks (you create a notebook and execute code as a set of “cells”, with results and documentation appearing inline), or as a more traditional text editor and IPython console.

To start a new notebook, select the Python 3 option from the menu. To execute a cell, enter the code you want to run and press Shift-Enter.

To start a new script, create a new file in the text editor and save it with an extension of “.py”. Right-clicking on the text editor will let you create a new Python 3 console for your session. You can execute code line-by-line using Shift-Enter.

More information about the JupyterHub interface can be found here. Adding new Jupyter kernels

JupyterHub is a web interface that sends commands to Python process running in the background. This Python process, called a kernel, is what is actually executing your code. We’ve setup JupyterHub with a few common kernels for common Python configurations and R. If you want to add a kernel (from say a custom Python environment or other programming language), follow the instructions for your kernel from here.

Note: conda is not recommended as it may lead to conflicts with the cvmfs software stack that is part of both CAC and the Digital Research Alliance of Canada. We strongly recommend using virtualenvironment instead.

Installing Python packages from Digital Research Alliance of Canada wheelhouse

The default python kernel on the launcher does not have access to Digital Research Alliance of Canada wheelhouse https://docs.alliancecan.ca/wiki/Available_Python_wheels. You can use the Frontenac cluster and/or the Terminal on the launcher window of JupyterHub to install required packages in a virtual environment and make it visible on your JupyterHub.

[user@caclogin03 ~]$ module load python/3.11
[user@caclogin03 ~]$ virtualenv my_env_py311
[user@caclogin03 ~]$ source my_env_py311/bin/activate
(my_env_py311) [user@caclogin03 ~]$ pip install numpy --no-index #include any required packages
(my_env_py311) [user@caclogin03 ~]$ pip install ipykernel --no-index
(my_env_py311) [user@caclogin03 ~]$ python -m ipykernel install --user --name my_env_py311 --display-name "my_env_py311_JH"
[user@caclogin03 ~]$ deactivate

Restart your JupyterHub session to view and use your virtual environment named my_env_py311_JH.

JupyterHub ipykernel.png

(Under Construction)