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 β
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:
sudo nano /etc/wsl.conf
Then input these lines inside the file
[network]
generateResolvConf = false
[boot]
systemd = true
Also, we need to setup the resolv.conf file for the DNS resolver
sudo nano /etc/resolv.conf
Then input these lines inside the file
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 β
sudo apt-get update && apt-get upgrade -y
sudo apt-get install -y --no-install-recommends ca-certificates netbase tzdata
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 β
sudo apt-get install -y git
3. Setup Python β
# 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
.
uv python install
to run the python, we should use uv python
command not only python
.
4. Setup PostgreSQL β
Install PostgreSQL from the repository
sudo apt-get install postgresql postgresql-contrib
TIP: Setting so PostgreSQL can be accessed by password
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
# 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 β
sudo rm -rf /var/lib/apt/lists/*