Setting up WSL and VSCode

This tutorial goes over installing WSL Version 1 (and in our case, we’ll be installing Ubuntu) and VSCode.

Start by installing VSCode. It’s a good idea to familiarize yourself with the VScode interface. Installing Ubuntu in WSL is a more involved process:

1. In the windows search bar, type “Turn Windows features on or off” (located in the control panel).

2. A new window will pop up with a list of checkboxes. Scroll down to “Windows Subsystem for Linux” and make sure that box is checked. Then click “OK”.

3. Once Windows has applied changes, click “Restart now” to reboot and enable WSL.

4. After reboot, open the Microsoft Store app from the search bar, and search for “Ubuntu”.

5. There are typically several Ubuntu version options. Choose the unversioned option (typically the first that pops up) and install.

6. A new bash terminal will pop up. Wait for the install to run, and create a username and password when prompted. Write your both of these down. If you forget your password, you’ll have to manually reset it from Windows later.

Setting up VSCode to run with Ubuntu WSL

Now that we have both installed, we need to tell VSCode to look for the WSL container.

1. Open VSCode, and if you do not have an Ubuntu bash (the term for a linux terminal) window open, do so by searching for “Ubuntu for Windows”.

2. In the bash window, type code . and hit enter. This command sets up the communication between VSCode and WSL


3. A new VSCode window will should pop up, and if it asks if you “trust the authors”, hit yes (that’s you).


4. You can exit out of the window that just popped up, and in your original VSCode window, hit “ctrl shift p” to open the command bar and type and run “Reload Window”. (If you notice I have a different tsdat pipeline from the original tutorial, don’t worry, the steps are the same.)


5. Once the VSCode window reloads, you’ll be able to search and find WSL commands. Open the command window (ctrl shift p) and search for “Reopen Folder in WSL”.



6. Wait for the window to reload and VSCode will start installing the necessary things. When it prompts you to install the recommended extensions, hit yes. You can close all the windows that pop up.


7. Occasionally VSCode will fail to import and extension for whatever reason. If it does, navigate to the extensions in the side bar and click the green “Install in WSL” button.

The full list of extensions you want installed are:
  • Python (Intellisense)

  • Pylance

  • Jupyter

  • Jupyter notebook renderer

  • Github pull requests

  • Code Runner

  • mplstyle

  • Todo Tree

  • YAML


8. When the “Pylance” extension installs, VSCode will prompt you to reload the window. Do so.


9. At some point VSCode will prompt you to “Reopen in dev container”. This refers to the docker container files. If you never intend to use docker, click “Don’t show again”


  1. You may also delete the Docker container files if you wish.


11. The next prompts from VSCode will likely be “<package> is not installed”. This is because we need to install python in the WSL environment, so ignore these for now.


Setting up Python in Ubuntu WSL

In these steps I’ll show you how to set up Miniconda in WSL. Miniconda is a barebones version of Anaconda that has all the same hardware, but doesn’t download Anaconda’s full suite of python packages, which saves disk space.

  1. Start by opening an Ubuntu bash and downloading Miniconda from the command line:

curl -sL "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" > "miniconda3.sh"

13. This command renames and saves the downloaded file with a simpler filename. Run the ‘.sh’ file with:

bash miniconda3.sh

14. This will start the install process. Scroll through the install process with the “enter” key, and type “yes” to the prompts as they pop up.





15. Once Miniconda3 finishes installing, it’ll ask you to “close and open your shell”. To do this, close the Ubuntu window, open up a Windows Powershell window, and type:

wsl --shutdown

If you don’t do this, you’ll get an http error anytime you try to run conda:


  1. Reopen an Ubuntu bash, and update conda:

    conda update conda
    
  2. Remove the Miniconda download file:

    rm miniconda3.sh
    
  3. And install “wget” if it wasn’t downloaded with conda:

    conda install wget
    

Open WSL Miniconda Environment in VSCode

Now that Ubuntu has a python environment set up, we need to open it in VSCode

1. Open up the vscode window and click the python version in the bottom right hand corner. This is our active python environment


2. In the command bar list that drops down, select the ‘base’ environment from miniconda. You’ll see the environment name change in the bottom toolbar.

Whenever you open WSL in VSCode, you’ll want to make sure the miniconda environment is running.


3. Everything should now be set up to run tsdat, so at this point we just need to install it. Type “ctrl `” to open the VSCode terminal. This should automatically open a new terminal window and a few lines of code should automatically run to activate the conda environment.


If the conda environment doesn’t activate, make sure the “CodeRunner” extension is installed.


4. Once the conda activate lines are run, install the pipeline required packages through the VSCode terminal:

pip install -r requirements.txt

Run the basic example pipeline

After tsdat installs, let’s make sure it can run.

1. Navigate to your “runner.py” file (Either in the example ingest-template or your own pipeline). In the top toolbar, there should be a dropdown beside the play bar. Select “Run Python Code”.


After the code runs, there won’t be any particular output in the terminal window. Notice that a new storage/ folder will be created.

If you are running a personal pipeline and get a “permissions denied” error, delete the original storage/ folder and let tsdat recreate the data through WSL. Windows does not allow WSL to alter folder permissions (https://github.com/microsoft/WSL/issues/81), so it can’t write to folders that it doesn’t originally create.