Skip to content

Instantly share code, notes, and snippets.



Last active Nov 23, 2020
What would you like to do?
Using the "black" Python formatter in VS Code

This is how to use the Black Python code formatter in VS Code.

Make a Python 3.6 virtualenv for running Black

Black itself requires Python 3.6 to run, but few of our projects are on that version. The VS Code plugin conveniently lets you run black from its own virtualenv.

I had to give a specific version of black this morning. I didn't yesterday. Don't specify the version unless it makes you (and if you do, give the current version, not the one from this doc).

$ cd ~/Envs
$ mkdir black
$ cd black
$ pipenv --python 3.6
$ pipenv install black==18.5b0
$ pipenv run which black

Take note of that last line!

Install the VS Code plugin for Black

Configure the plugin

Open your user settings and add:

    "[python]": {
        "editor.rulers": [
    "black.lineLength": 99,
    "black.path": "/Users/kirk/.local/share/virtualenvs/black-wkc_P2WA/bin/black",
    "python.formatting.provider": "none",


Now you can use the command palette to run "Format Document" to run Black on the current file. Down the road, we can set "editor.formatOnSave": true to automatically run it every time you save a file.


This comment has been minimized.

Copy link

@fredrike fredrike commented Aug 19, 2019

The plugin is deprecated and black is supported by the native Python package:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment