Commit 59d5382e authored by Etienne Kornobis's avatar Etienne Kornobis
Browse files

Add section on venv and on howto install jupyterlab with it

parent 5017ad66
%% Cell type:markdown id:systematic-springer tags:
%% Cell type:markdown id:expired-highway tags:
# Introduction to JupyterLab
## Aim of this section
- Whet your appetite on notebook technologies.
- Discover, get comfortable with Jupyterlab and create notebooks.
## Install
For more exhaustive guidelines, you can see [the official Jupyter documentation](
After creating a folder for the course, use `venv` to create a virtual environment named for example `sp_env`:
Using conda, create a ``jupyter`` environment with jupyter lab::
```python3 -m venv sp_env```
conda create -n jupyter jupyterlab
This will create a folder `sp_env` in your working directory. The corresponding virtual environment can be activated with:
Once installed, you can then activate the ``jupyter`` environment and start the jupyter server as follows::
```source sp_env/bin/activate```
conda activate jupyter
jupyter lab
You are now in a virtual environment. You can install librairies in it using pip and these will be installed specifically in this environment (and not globally on your machine). For more on virtual environment, [see the documentation](
Once the virtal environment activated, we can start composing this environment, now with jupyterlab
```pip install jupyterlab```
You can now start the jupyter server as follows:
```jupyter lab```
And open the specified URL in your internet browser (Chrome or Firefox are
better supported). By default, the address will be http://localhost:8888
better supported). By default, the address will be http://localhost:8888 and you will be automatically redirected to this tab.
Once all you work is done, you can exit the virtual environment with:
You will need to reactivate it (with `source sp_env/bin/activate`) in order to use it again.
For more exhaustive guidelines on JupyterLab installation, you can see [the official Jupyter documentation](
## Basic functioning of Jupyter notebooks
### Using the interface
......@@ -79,56 +94,56 @@
Here are some example of useful magic commands:
- Run cell with bash in subprocess:
%% Cell type:code id:wanted-ethiopia tags:
%% Cell type:code id:billion-actress tags:
``` python
echo "This is a bash script"
for i in {1..3}; do echo $i; done
echo "Over and out"
%% Cell type:markdown id:verbal-intake tags:
%% Cell type:markdown id:tight-spring tags:
- The exclamation mark character ``!`` can be used as well to execute the following line in a bash subprocess. For example:
%% Cell type:code id:naval-intensity tags:
%% Cell type:code id:helpful-oasis tags:
``` python
! echo "This is executed in a bash subprocess"
%% Cell type:markdown id:dynamic-heaven tags:
%% Cell type:markdown id:marked-construction tags:
- `%timeit` can be used to check for execution times:
%% Cell type:code id:above-recognition tags:
%% Cell type:code id:photographic-premises tags:
``` python
%timeit for _ in range(1000): True
%% Cell type:markdown id:simple-breathing tags:
%% Cell type:markdown id:sustained-render tags:
- Load more extension for the notebook, for example `autoreload` is useful extension to automatically reload a module imported in a Jupyter notebook if the module has changed locally:
%% Cell type:code id:grave-defense tags:
%% Cell type:code id:posted-pleasure tags:
``` python
%load_ext autoreload
%autoreload 2
%% Cell type:markdown id:suitable-paint tags:
%% Cell type:markdown id:insured-entertainment tags:
# Exercices
%% Cell type:markdown id:bright-original tags:
%% Cell type:markdown id:helpful-telephone tags:
The aim here is to get comfortable in Jupyterlab.
## Exercise
......@@ -136,34 +151,34 @@
- Create a new notebook with a python3 kernel.
- Create, delete and move cells around using shortcuts and graphical interface.
NB: A kernel provides a programming language support in Jupyter. Kernels are available for Python, R, Julia, and many more.
%% Cell type:code id:beneficial-ownership tags:
%% Cell type:code id:congressional-light tags:
``` python
%% Cell type:markdown id:frozen-mediterranean tags:
%% Cell type:markdown id:little-questionnaire tags:
## Exercise
In the notebook, create a code cell with simple python code inside with a
``print`` statement, execute the cell and witness its output.
For example::
print("Hello World !")
%% Cell type:code id:adjustable-scheme tags:
%% Cell type:code id:behavioral-ethnic tags:
``` python
%% Cell type:markdown id:owned-rings tags:
%% Cell type:markdown id:trained-advantage tags:
## Exercise
In the notebook, create a markdown cell with:
......@@ -172,17 +187,17 @@
- A list
- A link to the jupyter documentation ie
Render (execute) the cell to display the cell with a pretty formatting.
%% Cell type:code id:assumed-platinum tags:
%% Cell type:code id:phantom-register tags:
``` python
%% Cell type:markdown id:reported-planning tags:
%% Cell type:markdown id:precise-average tags:
## Exercise
Grasp the concept of cell execution by creating three cells:
......@@ -190,41 +205,41 @@
- 1 cell defining the same variable with a different value from the previous cell (e.g. `myvar=42`)
- 1 cell printing the value of the variable (`print(myvar)`).
Witness how execution order of your cells can affect the result of the cell printing the output. This is potentially dangerous when using notebooks and has to be kept in mind when coded and used.
%% Cell type:code id:residential-furniture tags:
%% Cell type:code id:solar-auckland tags:
``` python
%% Cell type:markdown id:surprising-interaction tags:
%% Cell type:markdown id:inside-approval tags:
## Exercise
Using a Jupyter magic command, create a cell listing the files in the current directory using a bash subprocess.
%% Cell type:code id:informed-parish tags:
%% Cell type:code id:worse-husband tags:
``` python
%% Cell type:markdown id:removed-devon tags:
%% Cell type:markdown id:dirty-speaker tags:
## Exercise
Using the graphical interface, export your notebook as html file.
%% Cell type:code id:absolute-indication tags:
%% Cell type:code id:injured-thirty tags:
``` python
%% Cell type:markdown id:thermal-karma tags:
%% Cell type:markdown id:perceived-michael tags:
# More documentation
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment