DEV Community

lostinopensource
lostinopensource

Posted on • Edited on

Python Development Environment on WSL2

This Post guides you through how to setup a python development environment on Windows Sub-System for Linux(wsl2).

What is WSL2?

wsl2 lets a windows user use a virtual linux environment on Windows Machine itself. This is pretty handy feature for quick development needs on your local machine.

Below Steps would list what all are the pre-requisites for achieving a python development environment on Windows Machine:

sudo apt update
sudo apt install python3 python3-pip python3-venv
Enter fullscreen mode Exit fullscreen mode

NOTE : Above command will install python3 , pip tool and python virtual environment package.

  • To create a Virtual Environment Open the WSL2 Terminal and create your python project directory using command mkdir <YOUR_PROJECT_NAME> and then inside create virtual environment using python3 -m venv .venv and to activate the environment run source .venv/bin/activate where .venv is your virtual environment name.

NOTE: Recommendation is creating the virtual environment inside the directory in which you plan to have your project. Since each project should have its own separate directory, each will have its own virtual environment, so there is not a need for unique naming

  • To exit from virtual environment run on wsl2 terminal: deactivate

Reference: https://learn.microsoft.com/en-us/windows/python/web-frameworks

Top comments (0)