|
|
@@ -0,0 +1,248 @@
|
|
|
+---
|
|
|
+marp: true
|
|
|
+title: Visual Studio Code for WSL
|
|
|
+author: P.Y. Barriat
|
|
|
+description: How to use VSCode with WSL
|
|
|
+backgroundImage: url('assets/back.png')
|
|
|
+_backgroundImage: url('assets/garde.png')
|
|
|
+footer: 01/06/2023 | Visual Studio Code for WSL | PY Barriat
|
|
|
+_footer: ""
|
|
|
+paginate: true
|
|
|
+_paginate: false
|
|
|
+math: true
|
|
|
+---
|
|
|
+
|
|
|
+Visual Studio Code for WSL<!--fit-->
|
|
|
+===
|
|
|
+
|
|
|
+https://gogs.elic.ucl.ac.be/pbarriat/learning-vscode
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+**Pierre-Yves Barriat**
|
|
|
+ELIC Training Sessions `June 13th, 2023`
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+# What is WSL :question:
|
|
|
+
|
|
|
+**Windows Subsystem for Linux** (WSL) allows you to leverage the benefits of Linux package management and command line tools to streamline your development workflow. This is particularly useful for web developers and **data scientists**
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+The easiest way to access your Ubuntu development environment in WSL is using **Visual Studio Code** via the built in *Remote extension*
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+# What is Visual Studio Code :question:
|
|
|
+
|
|
|
+**Visual Studio Code** (VS Code) is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux.
|
|
|
+
|
|
|
+It has a rich ecosystem of extensions for languages (such as C++, Fortran, Java, Python, etc) and runtimes (Git, Jupyter, etc)
|
|
|
+
|
|
|
+VSC is one of the most popular and powerful text editors used by software engineers today
|
|
|
+> free, open-source and [available](https://code.visualstudio.com/download) for macOS, Windows and Linux :+1:
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+# WSL on a Windows UCLouvain PC
|
|
|
+
|
|
|
+Linux from CII interface is **overkill**
|
|
|
+> based on Virtualbox: heavy workload :fearful:
|
|
|
+
|
|
|
+No auto process (yet) to install WSL from UCLouvain IT support
|
|
|
+
|
|
|
+You must install WSL by your own with the **Administrator access** from CII interface
|
|
|
+
|
|
|
+**Don't worry**: just follow the guideline below... :muscle:
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## Windows required features
|
|
|
+
|
|
|
+1. From CII interface, ask for an **Admin access**
|
|
|
+
|
|
|
+2. Open a **Powershell terminal** in **Administrator mode**
|
|
|
+
|
|
|
+3. Copy paste this line and press *Enter*
|
|
|
+
|
|
|
+```sh
|
|
|
+dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
|
|
|
+```
|
|
|
+
|
|
|
+4. Copy paste this line and press *Enter*
|
|
|
+
|
|
|
+```sh
|
|
|
+dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
|
|
|
+```
|
|
|
+5. Restart your computer
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## Install WSL2
|
|
|
+
|
|
|
+1. From CII interface, ask for an **Admin access**
|
|
|
+
|
|
|
+2. Download the **WSL2 update** and install it (double click on the file)
|
|
|
+
|
|
|
+ https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
|
|
|
+
|
|
|
+3. Open a **Powershell terminal** in **Administrator mode**
|
|
|
+
|
|
|
+4. Copy paste this line and press *Enter*
|
|
|
+
|
|
|
+```sh
|
|
|
+wsl --set-default-version 2
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## Install Ubuntu 22.04 from Microsft Store
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## First configuration of Ubuntu
|
|
|
+
|
|
|
+(Open Ubuntu) and choose a login/password
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+In the Ubuntu terminal do
|
|
|
+
|
|
|
+```bash
|
|
|
+sudo apt update
|
|
|
+
|
|
|
+sudo apt upgrade
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+# VS Code
|
|
|
+
|
|
|
+You can install Visual Studio Code from the web link [here](https://code.visualstudio.com/download)
|
|
|
+
|
|
|
+> during installation, under the **Additional Tasks step**, ensure the **Add to PATH** option is checked
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+Open VS Code and install **WSL for VS Code**
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+Connect to WSL using a **distro** (Ubuntu 22.04)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+Install extensions for **"WSL: Ubuntu 22.04"**
|
|
|
+
|
|
|
+- Python
|
|
|
+- Jupyter
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+# Jupyter Notebook in VS Code
|
|
|
+
|
|
|
+Create a new Juyter Notebook
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+Fill the first cell
|
|
|
+
|
|
|
+```python
|
|
|
+import numpy as np
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+Try to run the cell
|
|
|
+
|
|
|
+> you must choose a Python environment first : Python 3.6 and **Install**
|
|
|
+>
|
|
|
+> 
|
|
|
+> 
|
|
|
+
|
|
|
+But... :boom:
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+So open your first **WSL terminal** in VS Code
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+In this **Linux** terminal, do
|
|
|
+
|
|
|
+```bash
|
|
|
+sudo apt install python3-pip
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+Try again to run the cell !
|
|
|
+
|
|
|
+But now... :boom:
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+In your **Linux** terminal, install the missing Python extension ...
|
|
|
+
|
|
|
+```bash
|
|
|
+pip instal numpy
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+... and run the cell again: great, it's OK now :smiley:
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## Let's try a full notebook example
|
|
|
+
|
|
|
+First clone this **Git repository**
|
|
|
+
|
|
|
+```bash
|
|
|
+git clone https://gogs.elic.ucl.ac.be/pbarriat/learning-vscode
|
|
|
+```
|
|
|
+
|
|
|
+> You don't already know what's Git :question:
|
|
|
+> Shame on you ! :confounded:
|
|
|
+>
|
|
|
+> **It's not to late**: take a look here
|
|
|
+> https://gogs.elic.ucl.ac.be/TECLIM/Git_Training
|
|
|
+
|
|
|
+Now open the file `example.ipynb`
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+The first cell implies you must install some requirements
|
|
|
+
|
|
|
+To run this example, install the extensions below
|
|
|
+
|
|
|
+```bash
|
|
|
+pip install netCDF4
|
|
|
+sudo apt install libgeos-dev libgdal-dev
|
|
|
+pip install cartopy
|
|
|
+```
|
|
|
+
|
|
|
+Now, try to run all the cells of this notebook :exclamation:
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+# Visual Studio Code for WSL :speech_balloon:
|