Skip to content

How to Setup Your First WSL Distro for Python Development ​

In this time, we are going to use Debian distro which when this article is written has version 12. This blog article will explain the steps by Straight Through The Code, there is no much explanation that too long to read.

Installing WSL Distro ​

bash
wsl --install -d Debian

After that, we need to input some configurations:

  • New UNIX username
  • Password

Setup Systemd for WSL ​

It is best to config the systemd to your distro by this simple steps:

bash
sudo nano /etc/wsl.conf

Then input these lines inside the file

txt
[network]
generateResolvConf = false
[boot]
systemd = true

Also, we need to setup the resolv.conf file for the DNS resolver

bash
sudo nano /etc/resolv.conf

Then input these lines inside the file

txt
nameserver 8.8.8.8
nameserver 1.1.1.1

Then save it by Ctrl+S, then exit by Ctrl+X

Setup WSL Environment ​

1. Setup standard library ​

bash
sudo apt-get update && apt-get upgrade -y
bash
sudo apt-get install -y --no-install-recommends ca-certificates netbase tzdata
bash
sudo apt-get install -y --no-install-recommends dpkg-dev gcc gnupg libbluetooth-dev libbz2-dev libc6-dev libdb-dev libexpat1-dev libffi-dev libgdbm-dev liblzma-dev libncursesw5-dev libreadline-dev libsqlite3-dev libssl-dev make tk-dev uuid-dev wget xz-utils zlib1g-dev curl

2. Setup Git ​

bash
sudo apt-get install -y git

3. Setup Python ​

bash
# Install uv first for easy and python installation
curl -LsSf https://astral.sh/uv/install.sh | sh

Then, restart your shell/terminal to activate the new command uv.

bash
uv python install

to run the python, we should use uv python command not only python.

4. Setup PostgreSQL ​

Install PostgreSQL from the repository

bash
sudo apt-get install postgresql postgresql-contrib

TIP: Setting so PostgreSQL can be accessed by password

bash
sudo nano /etc/postgresql/<version>/main/pg_hba.conf

before: local allpostgres peer

after: local all postgres md5

Check does the postgresql service has been started

bash
# Checking service name, look for something like:
# [email protected] 
sudo systemctl list-units | grep postgresql

# Checking Status
systemctl status postgresql@15-main

# Start The Service
sudo systemctl start postgresql@15-main

5. Clean The Installation Setup Files ​

bash
sudo rm -rf /var/lib/apt/lists/*

Kevin Daffa Arrahman | Built with VitePress