Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't format Python file on Visual Studio Code: "There is no document formatter for 'python'-files installed."

I'm getting this message

There is no document formatter for 'python'-files installed.

When I try to format a Python file on Visual Studio Code.

I tried to install some packages (autopep8, pep8, pycodestyle), but they didn't help. What's going on?

like image 500
Marcel Avatar asked Sep 13 '25 22:09

Marcel


2 Answers

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).

like image 61
Brett Cannon Avatar answered Sep 15 '25 13:09

Brett Cannon


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!

like image 43
amirh_far Avatar answered Sep 15 '25 12:09

amirh_far