Visual Studio Code for WSL

https://forge.uclouvain.be/elic/learning.git

Pierre-Yves Barriat
ACELI Training Sessions March 25th, 2025

What is WSL ❓

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

25/03/2025 | Visual Studio Code for WSL | PY Barriat

What is Visual Studio Code ❓

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 for macOS, Windows and Linux 👍

25/03/2025 | Visual Studio Code for WSL | PY Barriat

WSL on a Windows UCLouvain PC

Linux from CII interface is overkill

based on Virtualbox: heavy workload 😨

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... 💪

25/03/2025 | Visual Studio Code for WSL | PY Barriat

25/03/2025 | Visual Studio Code for WSL | PY Barriat

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

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  1. Copy paste this line and press Enter
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  1. Restart your computer
25/03/2025 | Visual Studio Code for WSL | PY Barriat

Install WSL2

optional: it depends on your specific Windows 11 release (<1903)
if your build number is lower than 18362.1049

  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

wsl --set-default-version 2
25/03/2025 | Visual Studio Code for WSL | PY Barriat

Install Ubuntu 22.04 from Microsft Store

25/03/2025 | Visual Studio Code for WSL | PY Barriat

First configuration of Ubuntu

Open Ubuntu and choose a login/password

In the Ubuntu terminal do

sudo apt update
sudo apt upgrade
25/03/2025 | Visual Studio Code for WSL | PY Barriat

Graphical User Interface

Open a Powershell terminal in User mode and do

if your build number is lower than 18362.1049

wsl --update

maybe an Admin login/password is required (so ask for with CII interface)

Open a new Ubuntu terminal and do

sudo apt update
sudo apt upgrade
sudo apt install x11-apps -y
25/03/2025 | Visual Studio Code for WSL | PY Barriat

Install Visual Studio Code from Microsft Store

25/03/2025 | Visual Studio Code for WSL | PY Barriat

Open VS Code and install WSL for VS Code

25/03/2025 | Visual Studio Code for WSL | PY Barriat

Connect to WSL using Distro (Ubuntu 22.04)

25/03/2025 | Visual Studio Code for WSL | PY Barriat

Install extensions for "WSL: Ubuntu 22.04"

  • Python
  • Jupyter

25/03/2025 | Visual Studio Code for WSL | PY Barriat

Jupyter Notebook in VS Code

Create a new Juyter Notebook

Fill the first cell

import numpy as np
25/03/2025 | Visual Studio Code for WSL | PY Barriat

Try to run the cell

you must choose a Python environment first : Python 3.10 and Install


But... 💥

25/03/2025 | Visual Studio Code for WSL | PY Barriat

So open your first WSL terminal in VS Code

In this Linux terminal, do

sudo apt install -y python3-pip python3-ipykernel
25/03/2025 | Visual Studio Code for WSL | PY Barriat

Try again to run the cell !

Great, it's OK now 😃

25/03/2025 | Visual Studio Code for WSL | PY Barriat

Let's try a full notebook example

Install Git : sudo apt install -y git

Now clone this Git repository

git clone https://forge.uclouvain.be/elic/learning.git

You don't already know what's Git ? 😖

It's not to late: take a look here
learning/learning-git

Now go in the folder learning/learning-vscode/example and open the file example.ipynb

25/03/2025 | Visual Studio Code for WSL | PY Barriat

The first cell implies you must install some requirements

To run this example, install the extensions below

sudo apt install -y python3-netcdf4 python3-cartopy

Now, try to run all the cells of this notebook ❗

25/03/2025 | Visual Studio Code for WSL | PY Barriat

VS Code nice extensions

  • Remote - SSH : lets you use any remote machine with a SSH server
  • Tabnine : code faster with AI code completions
  • Regex Previewer : shows the current regular expression's matches
  • Modern Fortran : Fortran syntax is missing in built-in version
25/03/2025 | Visual Studio Code for WSL | PY Barriat

VSCode - Remote SSH : example

Select Remote-SSH: Open Configuration File

Host cyclone
    HostName cyclone.elic.ucl.ac.be
    User pbarriat

Visual Studio Code is now configured and ready to connect to your server :

click on the green Open a remote window button in the bottom left-hand corner and select Remote-SSH: Connect to Host

On ELIC workstation, choose a Python environment from ELIC_Python module : /opt/easybuild/...

25/03/2025 | Visual Studio Code for WSL | PY Barriat

Ubuntu with WSL (and without VS Code)

I strongly recommand to install Windows Terminal Preview from Microsft Store

25/03/2025 | Visual Studio Code for WSL | PY Barriat

Visual Studio Code for WSL 💬

25/03/2025 | Visual Studio Code for WSL | PY Barriat