In this article, I will explain how to create a Python execution environment that runs on Windows using VScode and WSL.
Before getting into the concrete construction method, I would like to explain the merits of choosing this among many Python execution environments.
First of all, by using VS Code for 1, the function to automatically adjust the appearance of the program such as step execution (execution while checking the behavior line by line) and auto format (spacing etc.) without making any special settings. ) Can be used. Next, regarding 2. This environment uses the virtual environment features that Python comes with by default. Therefore, you can manage packages on a command basis with pip. Also, by using it from VS Code, it is possible to easily switch between active virtual environments. Finally, regarding the third point. In the environment to be built this time, only the extensions Remote-WSL and Python are installed for VS Code, and Python is installed for WSL. You can choose and do everything from minimal construction to construction full of useful features using VS Code extensions.
Now let's check the actual construction procedure. Since many articles already exist, I will omit the installation of VS Code and WSL.
Python installation. Please enter a version specification if you like.
Create a project directory and create a virtual environment folder under it.
cd sample_project
python3 -m venv venv
Please install the extension "Remote-WSL". After that, open Remote-WSL once (lower left, green icon), and install the extension "Python" on the Remote-WSL side. (Extensions are managed separately on the Windows side and Remote-WSL side. Additional settings are required even if the Python extension is already installed)
Open the sample_project folder created on WSL from VS Code using the Remote-WSL function (from the menu File-> Open Folder). In this state, VS Code recognizes the virtual environment placed in the folder and automatically reads it. You can execute the code with the virtual environment in the folder activated by opening the .py file you want to execute and pressing the F5 key. You can also set breakpoints.