在 vscode 中使用黑色和 isort 自动保存时,isort 不起作用

Won*_*nee 5 python autosave isort

我想在 Visual Studio Code 中使用自动保存并应用 flake8、mypy、isort 和 black 等常用工具。

Flake8、mypy 和 black 工作正常,但 isort 根本不工作。有办法解决这个问题吗?

我的 settings.json 文件如下所示:

{
  "python.terminal.activateEnvInCurrentTerminal": false,
  "python.defaultInterpreterPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
  "python.linting.enabled": true,
  "python.linting.lintOnSave": true,
  "python.linting.pylintEnabled": false,
  "python.linting.flake8Enabled": true,
  "python.linting.flake8Path": "${workspaceFolder}\\.venv\\Scripts\\pflake8.exe",
  "python.linting.mypyEnabled": true,
  "python.formatting.provider": "black",
  "[python]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    },
    "editor.formatOnSave": true
  }
}
Run Code Online (Sandbox Code Playgroud)

小智 0

您可以尝试将以下行添加到 settings.json 文件中:

"python.sortImports.path": "${workspaceFolder}\\.venv\\Scripts\\isort.exe"

之后,保存 settings.json 文件并重新启动 VS Code。希望这个回答可以帮助到你