21

Opened a ticket with AutoPep8, but when I installed the autopep8 extension, it doesn't seem to find the module. When I change the config to tell it where it is a format doesn't do anything. Formating in terminal does however. Any ideas? https://github.com/hhatto/autopep8/issues/349#issuecomment-335662565

8
  • Can you show a picture of what is happening? What are you wanting from the formatting? Commented Oct 11, 2017 at 4:15
  • 1
    Have you tried the default Python extension yet? Commented Oct 12, 2017 at 15:19
  • Got a 404 on that link Commented Feb 12, 2018 at 23:36
  • 1
    Updated link: marketplace.visualstudio.com/items?itemName=ms-python.python Commented Feb 13, 2018 at 3:22
  • I installed that and I get the same result. Also it warns that its not a recommended interpretor. Commented Feb 15, 2018 at 2:07

5 Answers 5

18

Install the below python packages for Python Code Format supporting in Windows

pip install autopep8

pip install pylint

Once you have successfully installed the packages, Open the code in vs code -> Press Ctrl + A and Ctrl + K, it will format the code.

Sign up to request clarification or add additional context in comments.

1 Comment

This did not work for me. However, after running this command, I also went to the extensions of VSCode and installed the "autopep8" extensions. I then updated my user settings json file with "[python]": { "editor.defaultFormatter": "ms-python.autopep8"} and now VSCode is formatting my python code. This is on a mac, if that matters to you
7

autopep8 is listed as a requirement. On mac, using brew, you can install it as follows:

brew install autopep8

2 Comments

The other answer recommends pylint, is it needed for Mac to autoformat code?
This did not work for me. However, after running this command as well as the commands of pip install autopep8 and pip install pylint I installed a VSCode extensions called "autopep8". I wrote more specific instructions for making it work in a comment to an answer by @Dhandapani Sudhakar on this page you're currently on
5

you should try black.

pip install black

and then open the auto format option in vscode when save and modify the python format provider to black in vscode settings. enjoy the black.

Comments

2

after installation press ctrl + shift + F

Comments

1

You can use Ruff, it is suggested in the official VSCode documentation. Among their suggestions, it is the highest-rated community extension. Once installed, simply press

(CTRL or COMMAND) + ⇧ + i

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.