Helix/bwVisu/JupyterLab: Difference between revisions
m (Typo) |
H Schumacher (talk | contribs) m (Find the kernel section korrigiert) |
||
| (5 intermediate revisions by 3 users not shown) | |||
| Line 3: | Line 3: | ||
== Change Python Version == |
== Change Python Version == |
||
The default python version can be seen by running <code>python --version</code> in the terminal. |
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]]. |
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]]. |
||
| Line 11: | Line 11: | ||
Python packages can be added by installing them into a virtual environment and then creating an IPython kernel from the virtual environment. </br> |
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> |
<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. |
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 a virtual environment with... |
||
#* [[#Add_packages_via_venv_virtual_environments | ...venv]] or |
#* [[#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 |
#* [[#Add_packages_via_Conda_virtual_environments | ...conda]] (choose this option if you want to install a different python version) or |
||
#* ... |
#* [[#Add_packages_via_uv_virtual_environments | ...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 |
# [[#Create_an_IPython_Kernel | Create an IPython kernel]] from the virtual environment |
||
# Use the kernel within JupyterLab |
# 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. |
#* By default new kernels are saved under <code>~/.local/share/jupyter</code> and this location is automatically detected. Therefore, new kernels are directly available. |
||
#*:[[File:BwVisu JuypterLab KernelPath.png|In the JupyterLab job configuration form, a custom kernel path can be provided.|right|thumb|x150px]] |
#*:[[File:BwVisu JuypterLab KernelPath.png|In the JupyterLab job configuration form, a custom kernel path can be provided.|right|thumb|x150px]] |
||
#* If the kernel is saved somewhere else, the path can be provided in the "Kernel path" field when configuring the JupyterLab job (see image). For a kernel placed under <code>path_to_parent_dir/share/jupyter/kernels/my_kernel</code> the needed "Kernel path" would be <code>path_to_parent_dir/share/jupyter</code>. |
#* If the kernel is saved somewhere else, the path can be provided in the "Kernel path" field when configuring the JupyterLab job (see image). For a kernel placed under <code>path_to_parent_dir/share/jupyter/kernels/my_kernel</code> the needed "Kernel path" would be <code>path_to_parent_dir/share/jupyter</code>. |
||
# When the kernel is used the first time, the file <code>notebook_secrets</code> is created automatically. It can be found under "Kernel path". For others to use the kernel, they must have read access to this file. The command <code>chmod 750 notebook_secrets</code> would for example allow the whole SDS@hd SV read access. For the access management in workspaces, please see [[Workspace#Setting_Permissions_for_Sharing_Files| Workspace Permissions]]. |
# When the kernel is used the first time, the file <code>notebook_secrets</code> is created automatically. It can be found under "Kernel path". For others to use the kernel, they must have read access to this file. The command <code>chmod 750 notebook_secrets</code> would for example allow the whole SDS@hd SV read access. For the access management in workspaces, please see [[Workspace#Setting_Permissions_for_Sharing_Files| Workspace Permissions]]. |
||
<u>Notes regarding the sharing of IPython kernels</u> |
<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. |
* 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. |
* 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> |
* 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. |
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: |
Steps for creating a '''venv''' virtual environment: |
||
<ol style="list-style-type: decimal;"> |
<ol style="list-style-type: decimal;"> |
||
<li>Open a terminal.</li> |
<li>Open a terminal.</li> |
||
<li>Create a new virtual evironment: |
<li>Create a new virtual evironment: |
||
<syntaxhighlight lang="bash">python3 -m venv <env_parent_dir>/<env_name></syntaxhighlight> |
<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. |
* <code>env_parent_dir</code> 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. |
* Caution: If you you want to share the environment with others, make sure to already create it in the shared place. |
||
</li> |
</li> |
||
<li>Activate the environment: |
<li>Activate the environment: |
||
| Line 52: | Line 52: | ||
=== Add packages via Conda virtual environments === |
=== Add packages via Conda virtual environments === |
||
More information about using conda can be found at the [[Development/Conda | Conda]] page. |
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 miniforge module by clicking first on the |
<li>Load the miniforge module by clicking first on the double 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. |
||
<li>Open a terminal.</li> |
<li>Open a terminal.</li> |
||
<li>Create a new virtual environment: |
<li>Create a new virtual environment: |
||
* If you are the only person using the environment, you can install it in your home directory: |
* If you are the only person using the environment, you can install it in your home directory: |
||
<syntaxhighlight lang="bash">conda create --name <env_name> python=<python version></syntaxhighlight> |
<syntaxhighlight lang="bash">conda create --name <env_name> python=<python version></syntaxhighlight> |
||
| Line 65: | Line 65: | ||
</li> |
</li> |
||
<li>Activate your environment: |
<li>Activate your environment: |
||
<syntaxhighlight lang="bash">conda activate < |
<syntaxhighlight lang="bash">conda activate <env_name></syntaxhighlight></li> |
||
<li>Install your packages: |
<li>Install your packages: |
||
<syntaxhighlight lang="bash">conda install < |
<syntaxhighlight lang="bash">conda install <packagename></syntaxhighlight></li> |
||
<li> [[#Create_an_IPython_Kernel | Create an IPython kernel]]</li> |
<li> [[#Create_an_IPython_Kernel | Create an IPython kernel]]</li> |
||
</ol> |
</ol> |
||
=== Add packages via uv virtual environments === |
|||
More information about using <code>uv</code> can be found at the [[Development/Python | Python]] page. |
|||
Steps for creating a '''uv''' virtual environment: |
|||
<ol style="list-style-type: decimal;"> |
|||
<li>Open a terminal</li> |
|||
<li>Create a new project and virtual environment: |
|||
<syntaxhighlight lang="bash"> |
|||
uv init <env_parent_dir>/<env_name> |
|||
uv venv <env_parent_dir>/<env_name> --python <python version></syntaxhighlight> |
|||
* <code>env_parent_dir</code> is the path to the folder where the virtual environment shall be created. Relative paths can be used. |
|||
* The <code>--python <python_version></code> option can be omitted if the default Python version should be used. |
|||
* Caution: If you want to share the environment with others, make sure to |
|||
** Set your $HOME to the shared place before creating the environment: <code>HOME=<env_name></code> |
|||
** Create the environment directly in the shared place. |
|||
</li> |
|||
<li>Install packages into the environment: |
|||
<syntaxhighlight lang="bash">uv add <packagename></syntaxhighlight></li> |
|||
<li> [[#Create_an_IPython_Kernel | Create an IPython kernel]]</li> |
|||
</ol> |
|||
Unlike a traditional <code>venv</code> environment, a <code>uv</code> environment does not have to be activated with <code>source</code>. The <code>uv</code> commands can directly use the Python interpreter from the environment. |
|||
== Create an IPython Kernel == |
== Create an IPython Kernel == |
||
| Line 77: | Line 100: | ||
=== Create a kernel from a virtual environment === |
=== Create a kernel from a virtual environment === |
||
Please follow these instructions to create and find the kernel. |
|||
==== Step 1: Create the kernel ==== |
|||
'''Using venv or Conda''' |
|||
<ol> |
<ol> |
||
<li>Activate the virtual environment.</li> |
<li>Activate the virtual environment.</li> |
||
<li>Install the ipykernel package: |
<li>Install the ipykernel package: |
||
<syntaxhighlight lang="bash" |
<syntaxhighlight lang="bash"> |
||
pip install ipykernel |
|||
| ⚫ | |||
</syntaxhighlight> |
|||
</li> |
|||
| ⚫ | |||
* If you are the only person using the environment: |
* If you are the only person using the environment: |
||
<syntaxhighlight lang="bash">python3 -m ipykernel install --user --name=<kernel_name></syntaxhighlight> |
<syntaxhighlight lang="bash">python3 -m ipykernel install --user --name=<kernel_name></syntaxhighlight> |
||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
</syntaxhighlight> |
|||
| ⚫ | |||
| ⚫ | |||
</li> |
</li> |
||
</ol> |
</ol> |
||
'''Using uv''' |
|||
<ol> |
|||
<li>Install the ipykernel package: |
|||
<syntaxhighlight lang="bash"> |
|||
uv add ipykernel</syntaxhighlight></li> |
|||
<li>Register the virtual environment as custom kernel to Jupyter. |
|||
* If you are the only person using the environment: |
|||
<syntaxhighlight lang="bash">uv run ipython kernel install --user --env VIRTUAL_ENV $(pwd)/.venv --name=<kernel_name></syntaxhighlight> |
|||
* If you installed the environment in a shared place and want to have the kernel there as well: |
|||
<syntaxhighlight lang="bash">uv run ipython kernel install --prefix <path_to_kernel_folder> --env VIRTUAL_ENV $(pwd)/.venv --name=<kernel_name> |
|||
</syntaxhighlight> |
|||
</li> |
|||
</ol> |
|||
==== Step 2: Find the kernel ==== |
|||
* Private kernel: |
|||
| ⚫ | |||
* Shared kernel: |
|||
| ⚫ | |||
=== Multi-Language Support === |
=== Multi-Language Support === |
||
| Line 140: | Line 191: | ||
<ol><li>'''How can I use bwForCluster Helix software modules?'''</br> |
<ol><li>'''How can I use bwForCluster Helix software modules?'''</br> |
||
First click on the |
First click on the double hexagon icon on the left-hand side of Jupyter's start page. Then load a module by clicking on the "load" button next to the corresponding module entry.</li> |
||
<li>'''My virtual environment works on Helix but not in the bwVisu JupyterLab job.'''</br> |
<li>'''My virtual environment works on Helix but not in the bwVisu JupyterLab job.'''</br> |
||
If the environment uses Helix modules, you have to load the modules in the bwVisu job first. For example, when you used the python 3.13 module for creating the environment, the path to this python version is saved in the environment. When the module is not loadedin bwVisu, the path is not available and you might get an error like "''[...]/bin/python: error while loading shared libraries: libpython3.13.so.1.0: cannot open shared object file: No such file or directory''"</li> |
If the environment uses Helix modules, you have to load the modules in the bwVisu job first. For example, when you used the python 3.13 module for creating the environment, the path to this python version is saved in the environment. When the module is not loadedin bwVisu, the path is not available and you might get an error like "''[...]/bin/python: error while loading shared libraries: libpython3.13.so.1.0: cannot open shared object file: No such file or directory''"</li> |
||
| Line 146: | Line 197: | ||
Please see the instructions at the [[Helix/bwVisu/Usage#Files | Usage]] page.</li> |
Please see the instructions at the [[Helix/bwVisu/Usage#Files | Usage]] page.</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 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 | |
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> |
||
<li>'''My conda commands are interrupted with message 'Killed'.'''</br> |
<li>'''My conda commands are interrupted with message 'Killed'.'''</br> |
||
Request more memory when starting Jupyter.</li> |
Request more memory when starting Jupyter.</li> |
||
Latest revision as of 19:58, 8 October 2026
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/jupyterand 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 configuring the JupyterLab job (see image). For a kernel placed under
path_to_parent_dir/share/jupyter/kernels/my_kernelthe needed "Kernel path" would bepath_to_parent_dir/share/jupyter.
- By default new kernels are saved under
- When the kernel is used the first time, the file
notebook_secretsis created automatically. It can be found under "Kernel path". For others to use the kernel, they must have read access to this file. The commandchmod 750 notebook_secretswould for example allow the whole SDS@hd SV read access. For the access management in workspaces, please see Workspace Permissions.
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_diris 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 --no-user # when the environment is installed in home pip install <packagename> # when the environment is installed somewhere else and shall not have dependencies in home so that others can access it as well pip install <packagename> --no-user
- 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 double 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 <env_name>
- Install your packages:
conda install <packagename>
- Create an IPython kernel
Add packages via uv virtual environments
More information about using uv can be found at the Python page.
Steps for creating a uv virtual environment:
- Open a terminal
- Create a new project and virtual environment:
uv init <env_parent_dir>/<env_name> uv venv <env_parent_dir>/<env_name> --python <python version>
env_parent_diris the path to the folder where the virtual environment shall be created. Relative paths can be used.- The
--python <python_version>option can be omitted if the default Python version should be used. - Caution: If you want to share the environment with others, make sure to
- Set your $HOME to the shared place before creating the environment:
HOME=<env_name> - Create the environment directly in the shared place.
- Set your $HOME to the shared place before creating the environment:
- Install packages into the environment:
uv add <packagename>
- Create an IPython kernel
Unlike a traditional venv environment, a uv environment does not have to be activated with source. The uv commands can directly use the Python interpreter from the environment.
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
Please follow these instructions to create and find the kernel.
Step 1: Create the kernel
Using venv or Conda
- 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>
- 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>
Using uv
- Install the ipykernel package:
uv add ipykernel
- Register the virtual environment as custom kernel to Jupyter.
- If you are the only person using the environment:
uv run ipython kernel install --user --env VIRTUAL_ENV $(pwd)/.venv --name=<kernel_name>
- If you installed the environment in a shared place and want to have the kernel there as well:
uv run ipython kernel install --prefix <path_to_kernel_folder> --env VIRTUAL_ENV $(pwd)/.venv --name=<kernel_name>
Step 2: Find the kernel
- Private kernel:
- The kernel can be found under
~/.local/share/jupyter/kernels/.
- The kernel can be found under
- Shared kernel:
- The kernel can be found under
path_to_kernel_folder/share/jupyter/kernels/<kernel_name>. As long as the samepath_to_kernel_folderis used, all kernels will be saved next to each other in "kernels".
- The kernel can be found under
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
- How can I use bwForCluster Helix software modules?
First click on the double hexagon icon on the left-hand side of Jupyter's start page. Then load a module by clicking on the "load" button next to the corresponding module entry. - My virtual environment works on Helix but not in the bwVisu JupyterLab job.
If the environment uses Helix modules, you have to load the modules in the bwVisu job first. For example, when you used the python 3.13 module for creating the environment, the path to this python version is saved in the environment. When the module is not loadedin bwVisu, the path is not available and you might get an error like "[...]/bin/python: error while loading shared libraries: libpython3.13.so.1.0: cannot open shared object file: No such file or directory" - How can I navigate to my SDS@hd folder in the file browser?
Please see the instructions at the Usage page. - 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. - My conda commands are interrupted with message 'Killed'.
Request more memory when starting Jupyter. - 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.