2

enter image description hereI'm very confused about how it automatically format code in VS Code.

Below is a very clean, brand new environment for using Python.

When I write a test.py and press Save, prompt me for this information in the lower right corner, but I have installed these globally.

I had read this Automatically reformat Python code in VS Code . However , I can't comment it.

My workspace `settings.json`

{
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.fixAll.eslint": true
  },
  "python.defaultInterpreterPath": "C:\\Users\\admin\\anaconda3",
  "python.linting.enabled": true,
  "python.linting.pylintEnabled": true,
  "python.linting.lintOnSave": true,
  "python.linting.pycodestyleEnabled": true,
  "python.linting.flake8Enabled": true,
  "python.formatting.provider": "autopep8",
  "python.languageServer": "Pylance",
  "[python]": {
    // "editor.defaultFormatter": "ms-python.python",
    "editor.formatOnSave": true,
  },
}
6
  • 1
    you need to install the formatter to be able to use it. Just click "install" on the prompts Commented Mar 21, 2022 at 16:50
  • If prompts do not appear, you can do this by navigating to the "Extensions" tab (CTRL+Shift+X) and searching for Python. Commented Mar 21, 2022 at 16:54
  • The location where pylint et al. are installed, is that in the global PATH variable? Commented Mar 21, 2022 at 19:16
  • @md2perpe yeah,I'm sure pylint、flake8、yapf are in the global. Instead, they do not exist in the project local environment(conda interpreter) Commented Mar 22, 2022 at 5:01
  • @Cheese The code has a red prompt but cannot be formatted automatically Commented Mar 22, 2022 at 5:02

1 Answer 1

0

Obviously, the extensions you installed do not contain formatting extensions. You just need to click "Install" according to the prompt in the lower right corner. Of course, I suggest your adding the following two lines to the setting.json file so that you can format it automatically when editing and saving. "editor.formatOnType": true, "editor.formatOnSave": true,

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

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.