Configuring Black code formatter in VSCode

To configure VS Code to format a python file with Black automatically when it is saved:

  1. Install black (in macOS I used brew). This will install back in /usr/local/bin/black

  2. In VS Code settings (Code > Preferences > Settings), search for “python formatting provider” and select “black”

    vscode settings

  3. In VS Code settings (Code > Preferences > Settings), search for “format on save” and check the box

    vscode settings

  4. In VS Code settings (Code > Preferences > Settings), search for “black path” and set the path for black to /usr/local/bin/black

    vscode settings

updatedupdated2020-12-172020-12-17