Create a Python development environment on Windows (Visual Studio Code remote WSL).

https://www.youtube.com/watch?v=eiqXgj9EUnc

Detailed explanation with video on Ichiou Youtube!

motivation Since I reinstalled my Windows PC, I decided to build a new environment. I used to use PyCharm until now, but I used VS Code when developing on a Macbook on the go, so I want to unify the environment. I want to use remote WSL somehow

By the way, there are various things and I am using WSL2. In other words, the OS is Windows 10 Pro Insider Preview

Goal The goal this time is to run the Python Pyramid sample I made earlier https://github.com/YukiMiyatake/YukiMiyatakeWorks/tree/prj/Python/Pyramid/main

Python settings

miniconda installation

Python has a Python version control system called Anaconda Anaconda comes with so many packages such as machine learning Use Miniconda with the smallest package Of course, the required packages can be installed individually

https://docs.conda.io/en/latest/miniconda.html Get the installer for Linux from. Don't use it for Windows! !!

Then launch and install the downloaded shell script

VS Code settings

VS Code installation

Omitted

Open with remote WSL

It is usually opened on Windows. WSL is not written in the green part at the bottom left of VS Code. So let's reopen it with remote WSL Click the green part at the bottom left Remote-WSL:New Window To choose.

A new window will pop up, but make sure you see the WSL text in the green area at the bottom left. And I choose OpenFolder, but if I choose a folder from ShowLocal, it will be Windows. Enter the WSL path and press OK By default, the C drive is / mnt / c, but the setting has been changed to / c. I wrote about that in another Qiita

Type python or conda from Terminal and see what you just installed

Insert various plugins

Put what you need, such as Python snippets

setup.py Install the required packages

$ python setup.py develop

Command line execution

First, execute it from the command line and check it with a browser.

$ pserve development.ini

Launch with Debug from VS Code

Set launch.json

{
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "Python: Testapp",
            "type": "python",
            "request": "launch",
            "module": "pyramid.scripts.pserve",
            "args": [
                "${workspaceFolder}/development.ini"
            ],
            "pyramid": true,
            "jinja": true
        }
    ]
}

OK if you set a breakpoint, debug and stop

Linter settings

Pylint is too strict, so I decided to use flake8 However, flake8 does not fix it automatically, so use black for the auto formatter.

Install flake8 and black with conda or pip

Set Linter in Preference

flake8 points out a line break at 79 characters, but black makes a line break at 88 lines Therefore, if it is 80 to 88 characters, flake8 will remain pointed out. Set flake8 to 88 character line feed

Let's set the arguments of flake8 from Preference

I set it to format with black when saving the file, so check it

UnitTest This time we will use unittest.py

First, make sure you can hit unittest from the command line

However, since the test cannot be debugged as it is, set it with VS Code.

Set the unit test from the command palette (Ctrl + Shift + P) After setting this properly, if you execute a test from the command palette Results appear in the Test menu This time I got two test failures

You can retest from the menu, set breakpoints and debug the test.

The above is a memo to create a Python development environment with VisualStudioCode remote WSL on Windows.

Recommended Posts

Create a Python development environment on Windows (Visual Studio Code remote WSL).
Create a Python virtual development environment on Windows
Try to create a python environment with Visual Studio Code & WSL
Create a comfortable Python 3 (Anaconda) development environment on windows
Python development environment with Windows + Anaconda3 + Visual Studio Code
Python development environment with Windows + Python + PipEnv + Visual Studio Code
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
Set up a Python development environment with Visual Studio Code
Create a Python environment for professionals in VS Code on Windows
Create a Python execution environment for Windows with VScode + Remote WSL
Build Python development environment with Visual Studio Code
Steps to create a Python virtual environment with VS Code on Windows
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build a GVim-based Python development environment on Windows 10 (1) Installation
Create a decent shell and python environment on Windows
Create a Python development environment on OS X Lion
Create a Python environment on Mac (2017/4)
Create a Linux environment on Windows 10
Create a python environment on centos
Install Python development environment on Windows 10
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Create a VS Code + Docker development environment on a Linux VM
Build a GVim-based Python development environment on Windows 10 (2) Basic settings
Install python and Visual Studio Code on windows10 (April 2020 version)
Create a python environment on your Mac
Creating a python virtual environment on Windows
Example of building python development environment on windows (wsl2, vscode, pipenv)
Create a simple Python development environment with VS Code and Docker
Use Jupyter Notebook with Visual Studio Code on Windows 10 + Python + Poetry + pyenv-win
Simply build a Python 3 execution environment on Windows
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)
Build a Python development environment on your Mac
[Venv] Create a python virtual environment on Ubuntu
Set up a Python development environment on Marvericks
Create a Python environment
Create a Python execution environment on IBM i
Build a Python development environment on Raspberry Pi
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
Notes on creating a python development environment on macOS Catalina
Create a python development environment with vagrant + ansible + fabric
Build a Python development environment on Mac OS X
Procedure for building a CDK environment on Windows (Python)
Build a Python development environment using pyenv on MacOS
Python + Kivy development on Windows
Build Python environment on Windows
Django environment development on Windows 10
Build python environment on windows
Python development in Visual Studio 2017
Python development in Visual Studio
Until you create a machine learning environment with Python on Windows 7 and run it
Enable the virtualenv Python virtual environment for Visual Studio Code
Building a Jupyter Lab development environment on WSL2 using Anaconda3
Prepare Python development environment with Mac + Windows + VisualStudio Code (Windows version)
Prepare Python development environment with Mac + Windows + VisualStudio Code (Mac version)
Do something like a Python interpreter in Visual Studio Code
Create a simple Python development environment with VSCode & Docker Desktop
Build Python3 for Windows 10 on ARM with Visual Studio 2019 (x86) on Windows 10 on ARM
Create a virtual environment for python on mac [Very easy]
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
Until building a Python development environment using pyenv on Ubuntu 20.04
Building a Python environment on Mac