Sunday 4 October 2020

Introduction to JupyterLab

JupyterLab is a new interface of Jupyter Notebook server. It is a web-based interactive development environment for Jupyter notebooks, code, and data.


Installation via Anaconda


env.yml file should contain:

name: my-env # arbitrary name
...
dependencies:
  - jupyter=1.0.0
  - jupyterlab=0.34.9
...
  - python=3.6.6 # for running python kernels
...


Let's first check that python we'll be using is the right one:

(my-env) $ which python
/home/bojan/anaconda3/envs/my-env/bin/python

(my-env) $ python --version
Python 3.6.6

To launch jupyter lab:

(my-env) $ jupyter-lab
[I 07:37:01.479 LabApp] JupyterLab extension loaded from /home/bojan/anaconda3/envs/my-env/lib/python3.6/site-packages/jupyterlab
[I 07:37:01.479 LabApp] JupyterLab application directory is /home/bojan/anaconda3/envs/my-env/share/jupyter/lab
[I 07:37:01.483 LabApp] Serving notebooks from local directory: /home/bojan/dev/github/jupyterlab-demo
[I 07:37:01.484 LabApp] The Jupyter Notebook is running at:
[I 07:37:01.484 LabApp] http://localhost:8888/?token=22151a5520697ab97bfe48f44bcdd6248a0c1bd7bc5100ff
[I 07:37:01.484 LabApp]  or http://127.0.0.1:8888/?token=22151a5520697ab97bfe48f44bcdd6248a0c1bd7bc5100ff
[I 07:37:01.484 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 07:37:01.491 LabApp] 
    
    To access the notebook, open this file in a browser:
        file:///home/bojan/.local/share/jupyter/runtime/nbserver-20890-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=22151a5520697ab97bfe48f44bcdd6248a0c1bd7bc5100ff
     or http://127.0.0.1:8888/?token=22151a5520697ab97bfe48f44bcdd6248a0c1bd7bc5100ff
Opening in existing browser session.
[1004/073701.855894:ERROR:nacl_helper_linux.cc(308)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly
[I 07:37:24.221 LabApp] Kernel started: 8144639c-36e9-41ec-8e0c-06b9c593a426
[I 07:37:24.780 LabApp] Build is up to date
[I 07:37:46.613 LabApp] 302 GET /?token=22151a5520697ab97bfe48f44bcdd6248a0c1bd7bc5100ff (127.0.0.1) 0.66ms
[I 07:37:53.685 LabApp] Starting buffering for 8144639c-36e9-41ec-8e0c-06b9c593a426:3d1e75cf-7a1f-4999-a91a-013da0761314
[I 07:37:55.524 LabApp] Build is up to date
[I 07:38:59.153 LabApp] Saving file at /Untitled.ipynb
...
[I 07:46:51.165 LabApp] Starting buffering for 8144639c-36e9-41ec-8e0c-06b9c593a426:84ef87af-47d6-473a-b8a6-cbe3f2c0da45
[I 07:46:53.082 LabApp] Build is up to date
[I 07:46:55.971 LabApp] Starting buffering for 8144639c-36e9-41ec-8e0c-06b9c593a426:58fc2ee2-42b3-408d-baa9-b9d3fc5ba29c
^C[I 07:47:02.242 LabApp] interrupted
Serving notebooks from local directory: /home/bojan/dev/github/jupyterlab-demo
1 active kernel
The Jupyter Notebook is running at:
http://localhost:8888/?token=22151a5520697ab97bfe48f44bcdd6248a0c1bd7bc5100ff
 or http://127.0.0.1:8888/?token=22151a5520697ab97bfe48f44bcdd6248a0c1bd7bc5100ff
Shutdown this notebook server (y/[n])? y
[C 07:47:03.991 LabApp] Shutdown confirmed
[I 07:47:03.992 LabApp] Shutting down 1 kernel
[I 07:47:04.294 LabApp] Kernel shutdown: 8144639c-36e9-41ec-8e0c-06b9c593a426

We can see that jupyterlab starts a local web server which listens on port 8888. This is a classical Jupyter Notebook server (that's why we needed to include jupyter in the environment packages). We can then access it from a browser with http://localhost:8888 or http://127.0.0.1:8888. 

jupyterlab is an extension of this server:

(my-env) $ jupyter serverextension list
config dir: /home/bojan/anaconda3/envs/my-env/etc/jupyter
    jupyterlab  enabled 
    - Validating...
      jupyterlab 0.34.9 OK

jupyter lab is accessible at /lab path so when we run it, it will automatically open http://localhost:8888/lab in a browser.

We can also run jupyter notebook:

(my-env) $ jupyter notebook
[I 08:05:37.951 NotebookApp] JupyterLab extension loaded from /home/bojan/anaconda3/envs/my-env/lib/python3.6/site-packages/jupyterlab
[I 08:05:37.951 NotebookApp] JupyterLab application directory is /home/bojan/anaconda3/envs/my-env/share/jupyter/lab
[I 08:05:37.954 NotebookApp] Serving notebooks from local directory: /home/bojan/dev/github/jupyterlab-demo
[I 08:05:37.954 NotebookApp] The Jupyter Notebook is running at:
[I 08:05:37.954 NotebookApp] http://localhost:8888/?token=90194de8634a4a8e3c0ee9d4ec760382b4aa545d7b9260f6
[I 08:05:37.954 NotebookApp]  or http://127.0.0.1:8888/?token=90194de8634a4a8e3c0ee9d4ec760382b4aa545d7b9260f6
[I 08:05:37.954 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 08:05:37.960 NotebookApp] 
    
    To access the notebook, open this file in a browser:
        file:///home/bojan/.local/share/jupyter/runtime/nbserver-24138-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=90194de8634a4a8e3c0ee9d4ec760382b4aa545d7b9260f6
     or http://127.0.0.1:8888/?token=90194de8634a4a8e3c0ee9d4ec760382b4aa545d7b9260f6
Opening in existing browser session.
[1004/080538.264120:ERROR:nacl_helper_linux.cc(308)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly
[I 08:05:49.878 NotebookApp] Kernel started: 3aa4ef5c-e260-40af-8e54-a4f509223a64
[I 08:05:50.492 NotebookApp] Build is up to date
[I 08:06:31.324 NotebookApp] Saving file at /Untitled.ipynb




...and manually go to /lab:





References:

No comments: