L1 JupyterLab Overview
L1 JupyterLab Overview
The Navigator gives you a number of options. Click on Launch of the “JupyterLab” app (not
Jupyter Notebook) and a launcher window will open in your default web browser.
1
Click on “Notebook - Python 3” to start a new notebook.
On the left border of the notebook are a few tabs. By default you are in the ’File Browser’ and you
will see the current directory path and its files, including the new notebook in it. To change its
name right-click on the default name ’untitled.ipynb’ in the file browser and select ’Rename’. You
can also use the window to open PDF and picture files and (using the path at the top) navigate to
your preferred directory.
To test the new notebook, click on a code “cell” (it will get a blue frame when selected) and type
the following code:
Hello JupyterLab
Press shift-enter to execute the code. Alternatively, click the little right-faceing triangle above
the code.
The code instructs Python to display the text within quotes as an output below the code cell.
2
Python also accepts double quotes to mark the text. However, start and end quotes need to be
identical, they can’t be mixed. The following codes produces an error message (’throws an error’
in Python parlance):
The pink box contains the error message. If there is an error, the code was not executed. If your
next code depends on the output of the code in this cell, it can continue only after you have
resolved the problem. In the above case, the error message claims a ‘SyntaxError’. The interpreter
was expecting a closing ' to tell it where the text ends, but could not find it. Change the quotes to
be consistent and the code will be executed correctly.
Check the documentation of the JupyterLab environment for more details on how to work with
JupyterLab.
For any Python function you can access help using the help function. E.g to see the description of
the print function:
[4]: help(print)
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
We will have a look at the print function in the next part of the Lesson.
Idle or Busy
Check the little circle on the top right of the Notebook window: if it is empty (black circle, white
inside), Python is waiting for Input. If it is black inside, Python is busy. There is also a notice at
the bottom left: “Python 3 | idle” when it is waiting to get input.
If it stays black and you want to interrupt the programme, click on the black square of the tab
menu. When the circle is white, you can continue and all your variables should still be in the
workspace.
3
If it still stays black, go to the ‘Kernel’ tab of JupyterLab (not of the one of your web browser) and
in the menu click ‘Restart Kernel’. You can now continue but all your variables will be lost. Click
on cell number 1 and execute all cells until the one you were working in.
Folders and Current Directory
The current directory can be displayed or hidden clicking on the black ‘folder’ icon in the top left
corner of the JupyterLab window.
This allows you to see the current folder, its path and all files including subfolders. You can
navigate intuitively by clicking on the folder names. A number of common file types (including
images) can be opened by double clicking on their names.
By default every new notebook will be called “untitled. . . .ipynb” (with an automaticallyt increas-
ing number at the end). To change the name of a Jupyter notebook, select it and right click. From
the menu select “Rename”.
The fontsize of the code and text can be increased or decreased at the “zoom” symbol (a lens with
a plus in it) in the browser where the URL appears (right hand side).
Ways of Working
• You enter code in a cell and execute it.
• After execution a new cell will open and you can add new code etc.
• All code cells are marked “Code” in centre of the command bar at the top of the notrebook
window.
• You can switch a cell’s identity to “Markdown” from the drop-down menu under “Code”.
• Markdown cells can be used for text, images, links, tables etc. See for example this mark-
down cheetsheet.
Export
Jupyterlab notebooks can be exported to ascii, Latex, and executable Python script (extension .py).
In the JupyterLab window choose >File >Export Notebook As > and select from the options. Note
that export as PDF requires a separate extension to be installed.
For details please check the Jupyterlab documentation.
[ ]: