Helix/bwVisu/JupyterLab: Difference between revisions
H Winkhardt (talk | contribs) |
H Schumacher (talk | contribs) (Restructured page, improved explanation for sharing virtual environments) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[https://jupyter.org/ JupyterLab] is an integrated development environment (IDE) that provides a flexible and scalable interface for the Jupyter Notebook system. It supports interactive data science and scientific computing across over 40 programming languages (including Python, Julia, and R). |
[https://jupyter.org/ JupyterLab] is an integrated development environment (IDE) that provides a flexible and scalable interface for the Jupyter Notebook system. It supports interactive data science and scientific computing across over 40 programming languages (including Python, Julia, and R). |
||
== Python |
== Change Python Version == |
||
The default python version can be seen by running <code>python --version</code> in the terminal. |
|||
A different python version can be installed into a new virtual environment and then registered as IPython kernel for the usage in JupyterLab. This is explained in the chapter [[#Add_packages_via_conda_environments | add packages via conda environments]]. |
|||
<ol style="list-style-type: decimal;"> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
<li>Install the ipykernel package: |
|||
⚫ | |||
<li>Register your virtual environment as custom kernel to Jupyter: |
|||
⚫ | |||
<li>Select your newly created kernel in Jupyter</li></ol> |
|||
== Python |
== Install Python Packages == |
||
Python packages can be added by installing them into a virtual environment and then creating an IPython kernel from the virtual environment. </br> |
|||
<u>Kernels can be shared</u>. See the notes below. </br> |
|||
If you want to move a virtual environment, it is adivsed to recreate it in the new place. Otherwise, dependencies based on relative paths will break. |
|||
⚫ | |||
#* [[#Add_packages_via_venv_virtual_environments | ...venv]] or |
|||
#* [[#Add_packages_via_Conda_virtual_environments | ...conda]] (choose this option if you want to install a different python version) or |
|||
#* ...[https://docs.astral.sh/uv/getting-started/ uv] if you want to install a different python version but don't want to use conda. |
|||
# [[#Create_an_IPython_kernel | Create an IPython kernel]] from the virtual environment |
|||
# Use the kernel within JupyterLab |
|||
#* By default new kernels are saved under <code>~/.local/share/jupyter</code> and this location is automatically detected. Therefore, new kernels are directly available. |
|||
#* If the kernel is saved somewhere else, the path can be provided in the "Kernel path" field when submitting the job. For a kernel placed under <code>path_to_parent_dir/share/jupyter/kernels/my_kernel</code> the needed path would be <code>path_to_parent_dir</code>. |
|||
<u>Notes regarding the sharing of IPython kernels</u> |
|||
* The virtual environment and the kernel need to be placed in a shared directory. For example at SDS@hd. |
|||
* There could be a subdirectory for the virtual environments and one for the kernels. |
|||
* The path to the kernels is saved in the environment variable $JUPYTER_DATA_DIR. Jupyter relevant paths can be seen with <code>jupyter --paths</code> |
|||
=== Add packages via ''venv'' virtual environments === |
=== Add packages via ''venv'' virtual environments === |
||
More information about venv or other python virtual environments can be found at the [[Development/Python | Python]] page. |
|||
Steps for creating a '''venv''' virtual environment: |
|||
<ol style="list-style-type: decimal;"> |
<ol style="list-style-type: decimal;"> |
||
<li>Open a terminal |
<li>Open a terminal.</li> |
||
<li>Create a new virtual evironment: |
|||
<syntaxhighlight lang="bash">python3 -m venv < |
<syntaxhighlight lang="bash">python3 -m venv <env_parent_dir>/<env_name></syntaxhighlight> |
||
⚫ | |||
* <code>env_parent_dir</code> is the path to the folder where the virtual environment shall be created. Relative paths can be used. |
|||
<syntaxhighlight lang="bash">source <myEnv>/bin/activate</syntaxhighlight></li> |
|||
* Caution: If you you want to share the environment with others, make sure to already create it in the shared place. |
|||
⚫ | |||
</li> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
<syntaxhighlight lang="bash">pip install -U pip |
<syntaxhighlight lang="bash">pip install -U pip |
||
pip install < |
pip install <packagename></syntaxhighlight></li> |
||
<li> [[#Create_an_IPython_kernel | Create an IPython kernel]]</li> |
|||
<li>Install the ipykernel package: |
|||
</ol> |
|||
<syntaxhighlight lang="bash">pip install ipykernel</syntaxhighlight></li> |
|||
<li>Register your virtual environment as custom kernel to Jupyter: |
|||
⚫ | |||
=== Add packages via |
=== Add packages via Conda virtual environments === |
||
More information about using conda can be found at the [[Development/Conda | Conda]] page. |
|||
<ol style="list-style-type: decimal;"> |
<ol style="list-style-type: decimal;"> |
||
<li>Load the |
<li>Load the miniforge module by clicking first on the blue hexagon icon on the left-hand side of Jupyter's start page and then on the "load" button right of the entry for miniforge in the software module menu. |
||
Open a terminal |
<li>Open a terminal.</li> |
||
<li>Create a new virtual environment: |
|||
<pre>source $MINICONDA_HOME/etc/profile.d/conda.sh </pre></li> |
|||
* If you are the only person using the environment, you can install it in your home directory: |
|||
<li>Open a terminal and create a conda environment: |
|||
<syntaxhighlight lang="bash">conda create --name < |
<syntaxhighlight lang="bash">conda create --name <env_name> python=<python version></syntaxhighlight> |
||
* If you want to install it into a different directory, for example a shared place: |
|||
⚫ | |||
</syntaxhighlight> |
|||
</li> |
|||
<li>Activate your environment: |
<li>Activate your environment: |
||
<syntaxhighlight lang="bash">conda activate <myenv></syntaxhighlight></li> |
<syntaxhighlight lang="bash">conda activate <myenv></syntaxhighlight></li> |
||
<li>Install your packages: |
<li>Install your packages: |
||
<syntaxhighlight lang="bash">conda install <mypackage></syntaxhighlight></li> |
<syntaxhighlight lang="bash">conda install <mypackage></syntaxhighlight></li> |
||
<li> [[#Create_an_IPython_kernel | Create an IPython kernel]]</li> |
|||
</ol> |
|||
== Create an IPython Kernel == |
|||
Python kernels are implementations of the Jupyter notebook environment for different languages or virtual environments. You can switch between kernels easily, allowing you to use the best tool for a specific task. |
|||
conda_kernels |
|||
=== Create a kernel from a virtual environment === |
|||
<ol> |
|||
⚫ | |||
<li>Install the ipykernel package: |
<li>Install the ipykernel package: |
||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash">pip install ipykernel</syntaxhighlight></li> |
||
<li>Register |
<li>Register the virtual environment as custom kernel to Jupyter. |
||
* If you are the only person using the environment: |
|||
<syntaxhighlight lang="bash">python3 -m ipykernel install --user --name=<myKernel></syntaxhighlight></li></ol> |
|||
⚫ | |||
⚫ | |||
* If you installed the environment in a shared place and want to have the kernel there as well: |
|||
⚫ | |||
The kernel can then be found under <code>path_to_kernel_folder/share/jupyter/kernels/<kernel_name></code>. As long as the same <code>path_to_kernel_folder</code> is used, all kernels will be saved next to each other in "kernels". |
|||
</li> |
|||
</ol> |
|||
=== Multi-Language Support === |
=== Multi-Language Support === |
||
JupyterLab supports over 40 programming languages including Python, R, Julia, and Scala. This is achieved through the use of different kernels |
JupyterLab supports over 40 programming languages including Python, R, Julia, and Scala. This is achieved through the use of different kernels. |
||
⚫ | |||
==== R Kernel ==== |
==== R Kernel ==== |
||
Line 87: | Line 123: | ||
After that, Julia is available as a kernel. |
After that, Julia is available as a kernel. |
||
== Interactive Widgets == |
|||
JupyterLab supports interactive widgets that can create UI controls for interactive data visualization and manipulation within the notebooks. Example of using an interactive widget: |
JupyterLab supports interactive widgets that can create UI controls for interactive data visualization and manipulation within the notebooks. Example of using an interactive widget: |
||
Line 109: | Line 145: | ||
Try using more memory for the job. If this doesn't help, try using the inkognito mode of your browser as the browser cache might be the problem.</li> |
Try using more memory for the job. If this doesn't help, try using the inkognito mode of your browser as the browser cache might be the problem.</li> |
||
<li>'''I prefer VSCode over JupyterLab. Can I start a JupyterLab job and then connect with it via VSCode?'''</br> |
<li>'''I prefer VSCode over JupyterLab. Can I start a JupyterLab job and then connect with it via VSCode?'''</br> |
||
This |
This is not possible. Please start the job directly on Helix instead. You can find the instructions at the [[Development/VS_Code#Connect_to_Remote_Jupyter_Kernel | VSCode page]].</li> |
||
</ol> |
</ol> |
Latest revision as of 20:38, 28 August 2025
JupyterLab is an integrated development environment (IDE) that provides a flexible and scalable interface for the Jupyter Notebook system. It supports interactive data science and scientific computing across over 40 programming languages (including Python, Julia, and R).
Change Python Version
The default python version can be seen by running python --version
in the terminal.
A different python version can be installed into a new virtual environment and then registered as IPython kernel for the usage in JupyterLab. This is explained in the chapter add packages via conda environments.
Install Python Packages
Python packages can be added by installing them into a virtual environment and then creating an IPython kernel from the virtual environment.
Kernels can be shared. See the notes below.
If you want to move a virtual environment, it is adivsed to recreate it in the new place. Otherwise, dependencies based on relative paths will break.
- Create a virtual environment with...
- Create an IPython kernel from the virtual environment
- Use the kernel within JupyterLab
- By default new kernels are saved under
~/.local/share/jupyter
and this location is automatically detected. Therefore, new kernels are directly available. - If the kernel is saved somewhere else, the path can be provided in the "Kernel path" field when submitting the job. For a kernel placed under
path_to_parent_dir/share/jupyter/kernels/my_kernel
the needed path would bepath_to_parent_dir
.
- By default new kernels are saved under
Notes regarding the sharing of IPython kernels
- The virtual environment and the kernel need to be placed in a shared directory. For example at SDS@hd.
- There could be a subdirectory for the virtual environments and one for the kernels.
- The path to the kernels is saved in the environment variable $JUPYTER_DATA_DIR. Jupyter relevant paths can be seen with
jupyter --paths
Add packages via venv virtual environments
More information about venv or other python virtual environments can be found at the Python page.
Steps for creating a venv virtual environment:
- Open a terminal.
- Create a new virtual evironment:
python3 -m venv <env_parent_dir>/<env_name>
env_parent_dir
is the path to the folder where the virtual environment shall be created. Relative paths can be used.- Caution: If you you want to share the environment with others, make sure to already create it in the shared place.
- Activate the environment:
source <env_parent_dir>/<env_name>/bin/activate
- Update pip and install packages:
pip install -U pip pip install <packagename>
- Create an IPython kernel
Add packages via Conda virtual environments
More information about using conda can be found at the Conda page.
- Load the miniforge module by clicking first on the blue hexagon icon on the left-hand side of Jupyter's start page and then on the "load" button right of the entry for miniforge in the software module menu.
- Open a terminal.
- Create a new virtual environment:
- If you are the only person using the environment, you can install it in your home directory:
conda create --name <env_name> python=<python version>
- If you want to install it into a different directory, for example a shared place:
conda create --prefix <path_to_shared_directory>/<env_name> python=<python version>
- Activate your environment:
conda activate <myenv>
- Install your packages:
conda install <mypackage>
- Create an IPython kernel
Create an IPython Kernel
Python kernels are implementations of the Jupyter notebook environment for different languages or virtual environments. You can switch between kernels easily, allowing you to use the best tool for a specific task. conda_kernels
Create a kernel from a virtual environment
- Activate the virtual environment.
- Install the ipykernel package:
pip install ipykernel
- Register the virtual environment as custom kernel to Jupyter.
- If you are the only person using the environment:
python3 -m ipykernel install --user --name=<kernel_name>
The kernel can be found under
~/.local/share/jupyter/kernels/
.- If you installed the environment in a shared place and want to have the kernel there as well:
python3 -m ipykernel install --prefix <path_to_kernel_folder> --name=<kernel_name>
The kernel can then be found under
path_to_kernel_folder/share/jupyter/kernels/<kernel_name>
. As long as the samepath_to_kernel_folder
is used, all kernels will be saved next to each other in "kernels".
Multi-Language Support
JupyterLab supports over 40 programming languages including Python, R, Julia, and Scala. This is achieved through the use of different kernels.
R Kernel
- On the cluster:
$ module load math/R $ R > install.packages('IRkernel')
- On bwVisu:
- Start Jupyter App
- In left menu: load math/R
- Open Console:
- Start kernel 'R 4.2' as console or notebook
$ R > IRkernel::installspec(displayname = 'R 4.2')
Julia Kernel
Load the math/julia module. Open the Terminal.
julia ] add IJulia
After that, Julia is available as a kernel.
Interactive Widgets
JupyterLab supports interactive widgets that can create UI controls for interactive data visualization and manipulation within the notebooks. Example of using an interactive widget:
from ipywidgets import IntSlider slider = IntSlider() display(slider)
These widgets can be sliders, dropdowns, buttons, etc., which can be connected to Python code running in the backend.
FAQ
- My conda commands are interrupted with message 'Killed'.
Request more memory when starting Jupyter. - How can I navigate to my SDS@hd folder in the file browser?
Open a terminal and set a symbolic link to your SDS@hd folder in your home directory. For example: - Jupyterlab doesn't let me in but asks for a password.
Try using more memory for the job. If this doesn't help, try using the inkognito mode of your browser as the browser cache might be the problem. - I prefer VSCode over JupyterLab. Can I start a JupyterLab job and then connect with it via VSCode?
This is not possible. Please start the job directly on Helix instead. You can find the instructions at the VSCode page.
cd $HOME mkdir sds-hd cd sds-hd ln -s /mnt/sds-hd/sd16a001 sd16a001