Hyper Open Edge Cloud

HowTo Use Jupyter Inside Theia Runner

HowTo Use Jupyter Inside Theia Runner
  • Last Update:2023-01-03
  • Version:001
  • Language:en

Agenda

  1. Prerequisites
  2. Retrieve Jupyter connection parameters
  3. Upload files to Jupyter
  4. Access Jupyter files from Theia
  5. Create you own Python environment
  6. Create your own Jupyter kernel

This presentation aims to demonstrate how to use a Jupyter instance deployed inside a SlapOS Theia.

Prerequisites

This tutorial assumes you have access to a Theia Runner inside which a Jupyter has been deployed.   

Retrieve Jupyter connection parameters

Open a Theia terminal ( Menu > Terminal > New Terminal ) and type:

  • slapos service list to see all the instances deployed inside Theia as a list of instance names and software urls
  • slapos service info <instance name> to see the connection parameters for a specific instance (the name can be retrieved with the previous command)     

 Upload files to Jupyter


   

In this example we upload a screenshot image to Jupyter, but this may also be used to upload any kind of file, for example a zipped directory.

Access Jupyter files from Theia

The files in Jupyter (whether files uploaded to Jupyter or notebooks created by Jupter) can be accessed directly from Theia.

The first step is to find the directory reserved for the Jupyter instance: probably ~/srv/runner/slappart0, but if the Theia Runner contains several instances it could also be in slappart1, slappart2, ...
In order to be sure you can type: slapos node status and see in which slappart the Jupyter service is running.

The Jupyter files are then located in the var/notebooks subdirectory: ~/srv/runner/slappart0/var/notebooks.

You can either use a terminal or the Theia file explorer on the right to expand runner > instance > slappart0 > var > notebooks and open the files with the graphical interface.

For instance, if you've uploaded a zipped file to Jupyter, you can go to this location in the terminal and unzip it with the command line.

Create your own Python environment

If you have special Python library requirements, you might want to create a Python virtual environment and install your own packages.

> # create a virtual environment called myenv (creates a myenv folder in the current directory)
> python -m venv myenv
> # go to the myenv directory
> cd myenv
> # activate the environment
> source bin/activate
(myenv) > # when the environment is activated:
(myenv) > # - the prompt starts with (myenv)
(myenv) > # - you can install your dependencies locally with: pip install ...
(myenv) > # - the `python` command now refers to the virtual environment's python interpreter
(myenv) > # - this `python` has all your installed dependencies available

(myenv) > # you can deactivate and reactivate the environment at will
(myenv) > deactivate

Create your own Jupyter kernel

Once you have your own Python environment, you can add it a new Jupyter kernel and use it from Jupyter:

> # go to your environment directory and activate your virtual environment
> source bin/activate
(myenv) > # install ipykernel
(myenv) > pip install ipykernel
(myenv) > # add this Python virtual environment as a Jupyter kernel called mykernel
(myenv) > python -m ipykernel install --user --name=mykernel

You may need to reload the Jupyter page before your new kernel appears in the list.