I have these settings in vscode for the black extension in a poetry project, which uses system cache and poetry venv.
"editor.formatOnSave": true,
"python.formatting.provider": "black",
"python.formatting.blackPath": "path-to-/bin/black",
"python.pythonPath": "path-to-/python",
"python.linting.mypyEnabled": true,
"python.linting.mypyPath": "path-to-/bin/mypy"
I cannot understand why the formatter formats nothing. I am using local workspace settings ( above ).
Make sure black is installed in current used environment.
Open a integrated Terminal and activate the venv, run pip show black to see if it's installed in current environment. If not,
1.Comment these two settings;
"python.formatting.provider": "black",
"python.formatting.blackPath":"path-to-/bin/black",
2.Turn to python file, right click choose Format Document With... --> Python, there would be a prompt popping up to mention you install formatter, choose install black. After installation, the following setting will occur automatically in the Settings.json:
"python.formatting.provider": "black"
Then you can Format Document.

I found out that you must set the default formatter which is language specific.
For python this is ms-python.python extension by Microsoft, which allows a specific formatter to be enabled, e.g autopep8, black, yapf, etc. Note I was getting notification telling me that Extension 'prettier - Code formatter' cannot format file.py
"[python]": {
"editor.defaultFormatter": "ms-python.python",
}
Then include your actual formatter:
"python.formatting.provider": "black",
"python.formatting.blackPath": "/path/"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With