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 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
Omitted
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
Put what you need, such as Python snippets
setup.py Install the required packages
$ python setup.py develop
First, execute it from the command line and check it with a browser.
$ pserve development.ini
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
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.