Using autopep8 with Visual Studio Code

Using autopep8 with Visual Studio Code

by flandersen

Posted on July 11, 2020

autopep8 automatically formats Python code to conform to the PEP 8 style guide. It uses the pycodestyle utility to determine what parts of the code needs to be formatted. autopep8 is capable of fixing most of the formatting issues that can be reported by pycodestyle. –

Open your project folder in VScode.

Install autopep8 onto your system or virtualenv.

pip install autopep8

Now, add the following lines to .vscode/settings.json:

    "python.pythonPath": "d:\\PyTestProj\\.venv\\Scripts\\python.exe",
    "python.linting.pep8Enabled": true,
    "python.formatting.provider": "autopep8"

Important: Add a comma at the end of the first conifg.

In VScode, press CTRL+Shift+P which will then show you a list of commands. “autopep8” should be the first item. Acknowledge selection with the ENTER.