Update 2023-09-15:

Now VSCode has a Microsoft oficial Black Formatter extension. It will probably solve your problems.

Original answer:

I use Black from inside VSCode and it rocks. It frees mental cycles that you would spend deciding how to format your code. It's best to use it from your favorite editor. Just run from the command line if you need to format a lot of files at once.

First, check if you have this in your VSCode settings.json (open it with Ctrl-P + settings):

"python.formatting.provider": "black",
"editor.formatOnSave": true,

Remember that there may be 2 setting.json files: one in your home dir, and one in your project (.vscode/settings.json). The one inside the project prevails.

That said, these kind of problems usually are about using a python interpreter where black isn't installed. I recommend the use of virtual environments, but first check your python interpreter on the status bar:

If you didn't explicitly select an interpreter, do it now clicking on the Python version in your status bar. You can also do it with Ctrl-P + "Python: Select Interpreter". The status bar should change after selecting it.

Now open a new terminal. Since you selected your interpreter, your virtual environment should be automatically activated by VSCode. Run python using your interpreter path and try to import black:

$ python
Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import black
>>> 

Failed import? Problem solved. Just install black using the interpreter from the venv: python -m pip install black. You also can install using Conda, but in my experience VSCode works better with pip.

Still not working? Click in the "OUTPUT" tab sibling of the TERMINAL and try to get more info at the "Log" output (if you use the newer Black plugun it may be called "Black Formatter"). Select it in the pull down menu:

Answer from neves on Stack Overflow
๐ŸŒ
Visual Studio Code
code.visualstudio.com โ€บ docs โ€บ python โ€บ formatting
Formatting Python in VS Code
November 3, 2021 - Alternatively, you can set it as the default formatter for all Python files by setting "editor.defaultFormatter" in your User settings.json file, under a [python] scope. You can open settings.json with the Preferences: Open User Settings (JSON) command. For example, to set Black Formatter as the default formatter, add the following setting to your User settings.json file:
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
Black Formatter - Visual Studio Marketplace
Extension for Visual Studio Code - Formatting support for Python files using the Black formatter.
Discussions

python - Formatter black is not working on my VSCode...but why? - Stack Overflow
I have started using Python and Django and I am very new in this field. And, this is my first time to ask a question here...I do apologise in advance if there is a known solution to this issue... W... More on stackoverflow.com
๐ŸŒ stackoverflow.com
visual studio code - Python black formatter for vscode not formatting - Stack Overflow
I'm trying to use black as a formatter for Python on VS Code on Ubuntu 20.04 but it's not working on auto save. I've selected black in Python>Formatting:Provider. I'm using prettier as my default More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is the python formatting broken in VS Code?
I'm the creator of that video. The latest versions of VS Code no longer support the auto-formatting behavior I demonstrated. That said, I did the research, and if you want this formatting behavior, I show you how to get it back here: https://www.davegray.codes/posts/how-to-auto-format-unwanted-python-line-indents More on reddit.com
๐ŸŒ r/vscode
37
7
October 10, 2023
VS Code Python + Black formatter arguments - python.formatting.blackArgs - Stack Overflow
As of April 2024, I don't think python.formatting is recognized by vscode. ... As @Landon said same on black formatter v2024.2.0 and vscode 1.89.1. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
DEV Community
dev.to โ€บ adamlombard โ€บ how-to-use-the-black-python-code-formatter-in-vscode-3lo0
VSCode: Using Black to automatically format Python - DEV Community
April 4, 2024 - Open your VSCode settings, by going 'Code -> Preferences -> Settings'. Search for "python formatting provider" and select "black" from the dropdown menu:
Top answer
1 of 16
128

Update 2023-09-15:

Now VSCode has a Microsoft oficial Black Formatter extension. It will probably solve your problems.

Original answer:

I use Black from inside VSCode and it rocks. It frees mental cycles that you would spend deciding how to format your code. It's best to use it from your favorite editor. Just run from the command line if you need to format a lot of files at once.

First, check if you have this in your VSCode settings.json (open it with Ctrl-P + settings):

"python.formatting.provider": "black",
"editor.formatOnSave": true,

Remember that there may be 2 setting.json files: one in your home dir, and one in your project (.vscode/settings.json). The one inside the project prevails.

That said, these kind of problems usually are about using a python interpreter where black isn't installed. I recommend the use of virtual environments, but first check your python interpreter on the status bar:

If you didn't explicitly select an interpreter, do it now clicking on the Python version in your status bar. You can also do it with Ctrl-P + "Python: Select Interpreter". The status bar should change after selecting it.

Now open a new terminal. Since you selected your interpreter, your virtual environment should be automatically activated by VSCode. Run python using your interpreter path and try to import black:

$ python
Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import black
>>> 

Failed import? Problem solved. Just install black using the interpreter from the venv: python -m pip install black. You also can install using Conda, but in my experience VSCode works better with pip.

Still not working? Click in the "OUTPUT" tab sibling of the TERMINAL and try to get more info at the "Log" output (if you use the newer Black plugun it may be called "Black Formatter"). Select it in the pull down menu:

2 of 16
68

2024/02/19 updated

The previous solution doesn't work anymore.

There're two issues:

  1. vscode has new official extension
  2. different black output from vscode extension and black in your python virtual environment

If you just want to use 'black' formatter and don't care issue #2. Just install vscode black extension

I revised my solution for issue #2
a. install black extension first
b. set up your virtual environment, install black init and set your project interpreter to it
c. go to user setting, set Black-formatter: Path to "black" in your virtual environment

"black-formatter.path": ["black"]

NOTE: Install 'black' in the python environment you need, remove global 'black'

===== Obselete solution for old vscode =====
Attach my finding for those who still can't solve the Black formatting issue in VS Code.

First, you have to install Black globally or locally (if you use virtual env like conda).

Then, make sure your VS settings as following, set python default formatter provider as 'black':

Finally, open settings.json of your VS Code, add the following segment for it.

"[python]": {
    "editor.defaultFormatter": null,
    "editor.insertSpaces": true,
    "editor.tabSize": 4,
    "editor.formatOnSave": true
}

The key point is:

"editor.defaultFormatter": null

If you still use "editor.defaultFormatter": "black" as many old posts suggest, the Black formatter will not work in newer VS Code.

Top answer
1 of 7
18

There are only a few settings you need to setup black as a formatter on VS Code. It seems you got most of it right, but I am doubtful about using relative paths for blackPath (VS Code should have shown an error if the path is indeed incorrect).

I suggest switching to absolute paths.

Here are my settings:

// User Settings

"editor.defaultFormatter": null,
"editor.formatOnSave": false,  // enable per language
"[python]": {
    "editor.formatOnSave": true
},
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/bin/black"

// Workspace Settings

"python.formatting.blackPath": "/absolute/path/to/venv/with/black",
"python.formatting.blackArgs": [
    "-l 120"
],

First of all, I suggest getting rid of the editor.defaultFormatter setting (or just set it back to the default null). Instead of setting a default for everything, configure your formatter for each language and for each extension. Here, it's null and then I configure python-specific settings then I have separate ones for other languages (ex. JS and C++). You mentioned something about Prettier, and that could be interfering with VS Code using black.

Second, make sure you are modifying the correct settings. VS Code has 3 sets of settings: User, Workspace, and Folder. I normally have the formatOnSave enabled for Python on the User settings, and provider set to black (using system-wide installed black). On a specific workspace, I have a virtual environment and I override the blackPath to the black specifically installed on that virtual environment. You can also just put all the settings in the User settings or use the same system-wide-installed black. But the main point here is to use absolute paths for both (basically copying the output of which black from the console).

Note that, if you specified blackPath to point to a particular virtual environment, make sure to select that same virtual environment on your workspace.

Lastly, you can check for any issues from the Output tab > Python:

2 of 7
2

I was also having the issue. What solved the issue for me was after downloading the Black formatter extension and once the document was open I did a right-click with the mouse and then press "format document". Choose black. I was good to go and had no more issues after that.

๐ŸŒ
Orchestra
getorchestra.io โ€บ guides โ€บ how-to-install-black-formatter-on-vs-code
How to Install Black Formatter on VS Code | Orchestra
February 10, 2026 - Learn how to install and configure Black Formatter on VS Code to streamline Python code formatting and ensure consistent code style.
๐ŸŒ
GitHub
github.com โ€บ microsoft โ€บ vscode-black-formatter
GitHub - microsoft/vscode-black-formatter: Formatting support for Python using the Black formatter ยท GitHub
A Visual Studio Code extension with support for the Black formatter. The extension ships with black=26.1.0. Note: The minimum version of Black this extension supports is 26.1.0. This extension includes support for all actively supported versions of the Python language.
Starred by 190 users
Forked by 45 users
Languages ย  Python 88.5% | TypeScript 11.1% | JavaScript 0.4%
Find elsewhere
๐ŸŒ
GitHub
gist.github.com โ€บ kstrauser โ€บ c0cf3c440c3bffed60cb8e85de7f6649
Using the "black" Python formatter in VS Code ยท GitHub
https://marketplace.visualstud... "python.formatting.provider": "none", Now you can use the command palette to run "Format Document" to run Black on the current file....
๐ŸŒ
StatusNeo
statusneo.com โ€บ home โ€บ software development โ€บ introducing black: the uncompromising python code formatter
Introducing Black: The Uncompromising Python Code Formatter - StatusNeo
October 23, 2023 - Now, whenever we type Python code in VSCode, Black will automatically format the code according to its rules. โ€œBlackโ€ is a powerful and opinionated Python code formatter that enforces a strict set of formatting rules, providing a consistent and clean coding style.
๐ŸŒ
GitHub
yellowduck.be โ€บ posts โ€บ vscode-setting-line-lengths-in-the-black-python-code-formatter
๐Ÿ”— VSCode: Setting line lengths in the Black Python code formatter
The docs for the Black Python code formatter say that the formatter "is not configurable". This is largely true, but if you have Black set up > to work in VSCode, you can configure the line length.
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to Install & Configure Black Formatter in VS Code for Python - YouTube
Make your Python code beautiful effortlessly! This quick guide shows you how to set up the Black Formatter in VS Code. Discover how to enable auto-formatting...
Published ย  July 24, 2025
๐ŸŒ
Orchestra
getorchestra.io โ€บ guides โ€บ black-formatter-not-working-vscode-fixes
Black Formatter Not Working: VSCode Fixes | Orchestra
December 10, 2024 - You can set the interpreter in VSCode by pressing Ctrl + Shift + P, typing Python: Select Interpreter, and choosing the correct environment. ... Ensure that your VSCode settings are configured to use Black as the default formatter.
๐ŸŒ
Microsoft Developer Blogs
devblogs.microsoft.com โ€บ dev blogs โ€บ microsoft for python developers blog โ€บ python in visual studio code โ€“ may 2018 release
Python in Visual Studio Code โ€“ May 2018 Release - Microsoft for Python Developers Blog
November 19, 2019 - To enable the Black formatter, go into File > User Preferences > Settings, and put the following setting in your User Settings (for settings for all workspaces) or Workspace settings (for the current workspace/folder).
๐ŸŒ
GitHub
gist.github.com โ€บ zerossB โ€บ 1a2b128cd378491fa26747dd7fd70bee
How to configure black in vscode ยท GitHub
"editor.codeActionsOnSave": { "source.organizeImports": true }, "editor.formatOnSave": true, "editor.formatOnPaste": true, "python.formatting.provider": "black", "python.formatting.blackArgs": [ "-t", "py37" ] ... Works for me! ... My vscode doesn't sync with my ~/.config/black configuration file.
๐ŸŒ
GitHub
github.com โ€บ microsoft โ€บ vscode-black-formatter โ€บ releases
Releases ยท microsoft/vscode-black-formatter
Formatting support for Python using the Black formatter - microsoft/vscode-black-formatter
Author ย  microsoft