DEV Community

Mingming Ma
Mingming Ma

Posted on

Python Black and Flake8 configuration in VS Code - As of November 3, 2023

Are you looking to set up a Python formatter and linter in Visual Studio Code (VS Code)? If you've recently tried to search for this information, you may have encountered outdated tutorials:

1

Well, things have become much simpler!

0. Install Python extension

1. Install Black Formatter extension

2. Install Flake8 extension

3. Configure Black

In the .vscode/settings.json file add editor.defaultFormatter and editor.formatOnSave settings:

{
    //...
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter",
        "editor.formatOnSave": true,
      }
    //...
}
Enter fullscreen mode Exit fullscreen mode

4. Configure Flake8 (Using Black with Flake8)

Add the .flake8 file (project folder):

[flake8]
max-line-length = 88
extend-ignore = E203, E704
Enter fullscreen mode Exit fullscreen mode

That's it! Enjoy hassle-free Python development with these extensions in place!

Top comments (0)