More than likely you installed autopep8 into a different interpreter/environment than you one have selected in VS Code. If you remove your formatter settings from your settings.json and then try formatting again, you will get prompted to choose and install a formatter (either autopep8, yapf, or black).
More than likely you installed autopep8 into a different interpreter/environment than you one have selected in VS Code. If you remove your formatter settings from your settings.json and then try formatting again, you will get prompted to choose and install a formatter (either autopep8, yapf, or black).
I had the same problem, but I was using Prettier. Thus it doesn't support python properly or vscode doesn't recognize it as python formatter.
I installed autopep8 for python in extentions bar. Then I configured the settings.json for user and workspace settings.json:
user settings:
"[python]": {
"editor.formatOnType": true,
"editor.defaultFormatter": "ms-python.autopep8"
},
workspace-settings:
"folders": [
{
"path": "."
}
],
"settings": {
"git.ignoreLimitWarning": true,
"python.defaultInterpreterPath": "path_to_your_project",
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
}
},
And it worked!
Videos
I have been using VS Code for as long as I can remember, but for a few days now, when I try to format any of my Python files, it shows the error:
There is no formatter for 'python' files installed. Install Formatter...
I have the Prettier extension installed, which I use to format other files too. The default formatter for Python is set to prettier. It works for all other files, like JS, Java, C++, etc. The error only arises for Python files.
Please tell me what I can do to make it work again. Thank You.
Once VSCode Python's format feature came from the python package, VSCode now offers smarter and more customizable extensions.
autopep8 and Black formatter were provided by Microsoft.
Ruff and yapf were provided by community.
Once you install a formatter extension, you can select it as the default formatter for Python files in VS Code by following the steps below:
- Open a Python file in VS Code.
- Right-click on the editor to display the context menu.
- Select Format Document With....
- Select Configure Default Formatter... from the drop-down menu.
- Select your preferred formatter extension from the list.
You could read document about Formatting in vscode-python for more details.
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
}
I use Ruff and those are the settings for python files. For me the editor.codeActionsOnSave did the trick.