Skip to content
Home » Easy Data Science Windows 10/WSL Dev Environment Setup

Easy Data Science Windows 10/WSL Dev Environment Setup

close up photography of black and green computer keyboard keys
technology computer desktop programming
Photo by Markus Spiske on Pexels.com

Preparing Windows

Basic setup needs from Microsoft docs here

Important things:

You need to have Windows Build 20262 or higher, and I think it’s just easier to sign up for the stable Insider build. To check, go to Windows Settings -> Update & Security. To enable Insider builds, go to Windows Insider Program in Update & Security. You can pick which branch you want to be on, and I usually sign up for Release Preview although Beta Channel is usually pretty good. Release Preview is like a slightly faster version of non Insider

Install WSL

After you’ve got the versions set up, you can install WSL (which defaults to Ubuntu, but you can pick an alternate distro). Open Powershell (maybe in Administrator mode)

And type

wsl --install

This may take a while and likely requires a reboot. After the reboot, I suggest opening WSL/Ubuntu and entering:

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install wget ca-certificates

Install Winget and Terminal

After your computer is back up, go to the Windows App Store and install App Installer or Winget CLI

Use Winget in Powershell type

winget install Microsoft.WindowsTerminal

or the Microsoft App Store to get Terminal.

Restart your shell after! That’s as easy as closing Powershell and opening it back up.

Configure Terminal to your liking

Use these docs to customize Terminal’s look

By combining with Windows Terminal Themes. I like Doom Peacock, but obviously it’s subjective and up to you! In fact I just switched to tokyonight but also thought about using DotGov =D

Basically, you open Terminal’s Settings, open settings.json via the gear in the bottom left, add an entry for the color scheme (the easiest way is to copy/paste the theme from somewhere else like Windows Terminal Themes, and admittedly this is easier with VS Code), and then have your profile use that color scheme! You can make more tweaks to Terminal’s appearance with those Microsoft docs, but I didn’t bother.

close up photography of black and green computer keyboard keys
Photo by Max DeRoin on Pexels.com

Install zsh

One advantage of using WSL is that you can now install zsh and especially Oh My Zsh!

Install zsh in WSL:

sudo apt-get install zsh

Install Oh My Zsh in WSL:

sh -c"$(curl -fsSLhttps://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

My preferred Oh My Zsh theme is Powerlevel10k which you can install in WSL by typing:

git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k

Then editing your ~/.zshrc with say

nano ~/.zshrc

and changing

ZSH_THEME="powerlevel10k/powerlevel10k"

Heads up: Terminal out of the box might have ugly colors for directories. Doom Peacock and Powerlevel10k seemed to fix those for me, but otherwise you can try following the steps here under Changing Directory Colors.

After you edit your /.zshrc you should also source ~/.zshrc in Terminal and maybe even close and re open it.

If you installed new fonts (like MesloLGS NF as recommended by Powerlevel10k), you should restart Terminal.

Install VS Code

I prefer VS Code and here are instructions on how to get it up and running with WSL.

Briefly, you can install it from the Windows Store, from the installer on the homepage or in Powershell Winget with

winget install Microsoft.VisualStudioCode

Important: install the Remote Development extension pack! Otherwise, you will get oddities and reduced performance with VS Code when you’re working inside WSL.

After you install VS Code, close and reopen your Terminal. This is to make sure VSCode gets added to your PATH and if you used winget to install, it’s possible you may have to install it the normal way anyway. I used winget, didn’t close Terminal, just ended up using the normal installer, and then restarting Terminal anyway.

Need to install GUI apps or use a GPU? You’re beyond my experience/needs with WSL, and I suggest fully reading the docs from Microsoft and NVIDIA.

In addition, there is a dedicated set of docs for Troubleshooting WSL.

python book
Photo by Christina Morillo on Pexels.com

Install ASDF

Ok, let’s move on to ASDF, which lets you install multiple versions of a tool (like Python 3.8 and 3.10)

Open a Terminal instance of WSL and type the following (we need more packages)

sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline-dev zlib1g-dev libncurses-dev libncursesw5-dev libffi-dev libgdbm-dev libc6-dev python-dev python-setuptools python-pip python-smbus libsqlite3-dev tk-dev openssl

apt install curl git

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0

Since we’re using zsh, we can follow the relevant steps from ASDF’s install guide: Add the following to ~/.zshrc:

. $HOME/.asdf/asdf.sh

OR use a ZSH Framework plugin like asdf for oh-my-zsh which will source this script and setup completions.

Completions are configured by either a ZSH Framework asdf plugin or by adding the following to your .zshrc:

# append completions to fpath
fpath=(${ASDF_DIR}/completions $fpath)

# initialise completions with ZSH's compinit
autoload -Uz compinit && compinit

• if you are using a custom compinit setup, ensure compinit is below your sourcing of asdf.sh • if you are using a custom compinit setup with a ZSH Framework, ensure compinit is below your sourcing of the framework

Restart shell with source

source ~/.zshrc

or opening a new tab!

Install Python with ASDF

Now we can install Python

In Terminal

asdf plugin add python

Pick which version you want with

asdf list all python

And then install with

asdf install python [version wanted]

If you get module missing errors, you may need to install some dependencies. If so, go install the missing ones, then use asdf to uninstall the Python version you were trying to install (asdf uninstall python [version]), and then reinstall Python.

When Python is installed, set your version globally (asdf global python [version]), but also set your version locally in each repo if you would like (asdf local python [version])

Install Poetry

What version of Python do you want to use? It influences which method of Poetry install you need to follow Introduction | Documentation | Poetry – Python dependency management and packaging made easy (python-poetry.org)

Or the Master branch Introduction | master | Documentation | Poetry – Python dependency management and packaging made easy (python-poetry.org) which is more modern and requires Python 3.7 or higher

Add autocompletion for Poetry!

mkdir $ZSH_CUSTOM/plugins/poetry
poetry completions zsh > $ZSH_CUSTOM/plugins/poetry/_poetry

You must then add poetry to your plugins array in ~/.zshrc:

plugins
    poetry
    ...
    )

Get coding!

If you read this all the way through, please let me know how it helped or what could be improved! You can reach me at the links below, or via the Contact Me page above

References:


Socials

1 thought on “Easy Data Science Windows 10/WSL Dev Environment Setup”

  1. Pingback: 2022.08.03 - Stream Notes - BuenosDS

Comments are closed.