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:
Installing WSL2: https://learn.microsoft.com/en-us/windows/wsl/install
Install Microsoft Visual Studio code for Windows platform: https://code.visualstudio.com/
Install the Remote WSL Extension on VSCode: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl
Once Wsl2 (at step 1) in installed open an Ubuntu terminal and verify if Python3 is installed using
python3 --version
.If Python3 is not installed then do the following:
sudo apt update
sudo apt install python3 python3-pip python3-venv
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 usingpython3 -m venv .venv
and to activate the environment runsource .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)