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:

python - Formatter black is not working on my VSCode...but why? - Stack Overflow
Python black formatting - ROS General - Open Robotics Discourse
visual studio code - Python black formatter for vscode not formatting - Stack Overflow
code formatting - In Python, how to tweak Black formatter, if possible? - Stack Overflow
Videos
I really don't understand why the Python Black formatter seems to be so popular. What is the point of a non-configurable and highly biased code formatter? I see no benefit in making all the code in the world look the same. They claim they are ending discussions about code formatting, but in reality they have sparked the biggest debate ever in the Python community with their subjective and often contradictory methods that have evolved over decades of established practices without the ability to configure the formatter. [1][2] The single/double quote disaster is just the most prominent example.
There are people out there who put readability above consistency with every other code base in the world that they will never come into contact with.
What bothers me most is the detachment of the Black developers, who dismiss all objections to their style choices as if they were opinions, and end every discussion by saying, you are just expressing an opinion and we prefer ours. But that is not true, there were many reasons, objectively measurable reasons, why this or that decision is better. Someone else might weigh these reasons differently and therefore come to a different conclusion. But the arguments used to enforce Black's decisions have never stood the test of time in a factual discussion.
I also notice that younger developers (< 35 years) are more likely to accept this approach than the more experienced ones.
[1] https://github.com/psf/black/issues/1252
[2] https://github.com/psf/black/issues/373
» pip install black
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:

2024/02/19 updated
The previous solution doesn't work anymore.
There're two issues:
- vscode has new official extension
- 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.
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:

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.
This is due to the default line length for black being longer than you'd like – 88 characters per line.
To decrease the line length, you can use the --line-length flag as documented here:
https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html
For example:
$ black --line-length 80 example.py
Black explains the --line-length setting in more detail here:
https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
Line length
You probably noticed the peculiar default line length. Black defaults to 88 characters per line, which happens to be 10% over 80. This number was found to produce significantly shorter files than sticking with 80 (the most popular), or even 79 (used by the standard library). In general, 90-ish seems like the wise choice.
If you're paid by the line of code you write, you can pass
--line-lengthwith a lower number. Black will try to respect that. However, sometimes it won't be able to without breaking other rules. In those rare cases, auto-formatted code will exceed your allotted limit.You can also increase it, but remember that people with sight disabilities find it harder to work with line lengths exceeding 100 characters. It also adversely affects side-by-side diff review on typical screen resolutions. Long lines also make it harder to present code neatly in documentation or talk slides.
Emphasis on the final paragraph.
I'd recommend just keeping the default settings. The beauty of Black is that it chooses for you, and therefor preempts any arguments about which way is "best".
This is now possible by adding a trailing comma to your last argument.
In your example you would write instead:
def example_function(
arg_1: str,
arg_2: bool,
arg_3: int = 0,
arg_4: int = 1,
arg_5: float = 0.0, # <-- Notice the trailing comma
):