From 59d5382eb9fbdf902522ac13ef8d9c7e800848e1 Mon Sep 17 00:00:00 2001
From: Etienne Kornobis <ekornobis@gmail.com>
Date: Fri, 24 Sep 2021 11:27:22 +0200
Subject: [PATCH] Add section on venv and on howto install jupyterlab with it

---
 notebooks/jupyter_practice.ipynb | 73 +++++++++++++++++++-------------
 1 file changed, 44 insertions(+), 29 deletions(-)

diff --git a/notebooks/jupyter_practice.ipynb b/notebooks/jupyter_practice.ipynb
index 66c78e6..e2421e6 100644
--- a/notebooks/jupyter_practice.ipynb
+++ b/notebooks/jupyter_practice.ipynb
@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "markdown",
-   "id": "systematic-springer",
+   "id": "expired-highway",
    "metadata": {},
    "source": [
     "# Introduction to JupyterLab\n",
@@ -14,19 +14,34 @@
     "\n",
     "## Install\n",
     "\n",
-    "For more exhaustive guidelines, you can see [the official Jupyter documentation](https://jupyter.org/install)\n",
+    "After creating a folder for the course, use `venv` to create a virtual environment named for example `sp_env`:\n",
     "\n",
-    "Using conda, create a ``jupyter`` environment with jupyter lab::\n",
+    "```python3 -m venv sp_env```\n",
     "\n",
-    "  conda create -n jupyter jupyterlab\n",
+    "This will create a folder `sp_env` in your working directory. The corresponding virtual environment can be activated with:\n",
     "\n",
-    "Once installed, you can then activate the ``jupyter`` environment and start the jupyter server as follows::\n",
+    "```source sp_env/bin/activate```\n",
     "\n",
-    "  conda activate jupyter\n",
-    "  jupyter lab\n",
+    "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](https://docs.python.org/3/library/venv.html).\n",
+    "\n",
+    "Once the virtal environment activated, we can start composing this environment, now with jupyterlab\n",
+    "\n",
+    "```pip install jupyterlab```\n",
+    "\n",
+    "You can now start the jupyter server as follows:\n",
+    "\n",
+    "```jupyter lab```\n",
     "\n",
     "And open the specified URL in your internet browser (Chrome or Firefox are\n",
-    "better supported). By default, the address will be http://localhost:8888\n",
+    "better supported). By default, the address will be http://localhost:8888 and you will be automatically redirected to this tab.\n",
+    "\n",
+    "Once all you work is done, you can exit the virtual environment with:\n",
+    "\n",
+    "```deactivate```\n",
+    "\n",
+    "You will need to reactivate it (with `source sp_env/bin/activate`) in order to use it again.\n",
+    "\n",
+    "For more exhaustive guidelines on JupyterLab installation, you can see [the official Jupyter documentation](https://jupyter.org/install)\n",
     "\n",
     "## Basic functioning of Jupyter notebooks\n",
     "\n",
@@ -90,7 +105,7 @@
   {
    "cell_type": "code",
    "execution_count": 13,
-   "id": "wanted-ethiopia",
+   "id": "billion-actress",
    "metadata": {},
    "outputs": [
     {
@@ -115,7 +130,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "verbal-intake",
+   "id": "tight-spring",
    "metadata": {},
    "source": [
     "- The exclamation mark character ``!`` can be used as well to execute the following line in a bash subprocess. For example:"
@@ -124,7 +139,7 @@
   {
    "cell_type": "code",
    "execution_count": 21,
-   "id": "naval-intensity",
+   "id": "helpful-oasis",
    "metadata": {},
    "outputs": [
     {
@@ -141,7 +156,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "dynamic-heaven",
+   "id": "marked-construction",
    "metadata": {},
    "source": [
     "- `%timeit` can be used to check for execution times:"
@@ -150,7 +165,7 @@
   {
    "cell_type": "code",
    "execution_count": 18,
-   "id": "above-recognition",
+   "id": "photographic-premises",
    "metadata": {},
    "outputs": [
     {
@@ -167,7 +182,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "simple-breathing",
+   "id": "sustained-render",
    "metadata": {},
    "source": [
     "- 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:"
@@ -176,7 +191,7 @@
   {
    "cell_type": "code",
    "execution_count": 22,
-   "id": "grave-defense",
+   "id": "posted-pleasure",
    "metadata": {},
    "outputs": [
     {
@@ -195,7 +210,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "suitable-paint",
+   "id": "insured-entertainment",
    "metadata": {},
    "source": [
     "# Exercices"
@@ -203,7 +218,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "bright-original",
+   "id": "helpful-telephone",
    "metadata": {},
    "source": [
     "The aim here is to get comfortable in Jupyterlab.\n",
@@ -220,14 +235,14 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "beneficial-ownership",
+   "id": "congressional-light",
    "metadata": {},
    "outputs": [],
    "source": []
   },
   {
    "cell_type": "markdown",
-   "id": "frozen-mediterranean",
+   "id": "little-questionnaire",
    "metadata": {},
    "source": [
     "## Exercise\n",
@@ -243,14 +258,14 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "adjustable-scheme",
+   "id": "behavioral-ethnic",
    "metadata": {},
    "outputs": [],
    "source": []
   },
   {
    "cell_type": "markdown",
-   "id": "owned-rings",
+   "id": "trained-advantage",
    "metadata": {},
    "source": [
     "## Exercise\n",
@@ -268,14 +283,14 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "assumed-platinum",
+   "id": "phantom-register",
    "metadata": {},
    "outputs": [],
    "source": []
   },
   {
    "cell_type": "markdown",
-   "id": "reported-planning",
+   "id": "precise-average",
    "metadata": {},
    "source": [
     "## Exercise\n",
@@ -292,14 +307,14 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "residential-furniture",
+   "id": "solar-auckland",
    "metadata": {},
    "outputs": [],
    "source": []
   },
   {
    "cell_type": "markdown",
-   "id": "surprising-interaction",
+   "id": "inside-approval",
    "metadata": {},
    "source": [
     "## Exercise\n",
@@ -310,14 +325,14 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "informed-parish",
+   "id": "worse-husband",
    "metadata": {},
    "outputs": [],
    "source": []
   },
   {
    "cell_type": "markdown",
-   "id": "removed-devon",
+   "id": "dirty-speaker",
    "metadata": {},
    "source": [
     "## Exercise\n",
@@ -328,14 +343,14 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "absolute-indication",
+   "id": "injured-thirty",
    "metadata": {},
    "outputs": [],
    "source": []
   },
   {
    "cell_type": "markdown",
-   "id": "thermal-karma",
+   "id": "perceived-michael",
    "metadata": {},
    "source": [
     "# More documentation\n",
-- 
GitLab