Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode: how to config 'Organize imports' for Python (isort)

Mirror question to:

  • "How to config VSCode's Organize Imports order?" which refers to a .js project.

I want to configure how VSCode is invoking isort, so I can customize when calling Organize imports in a .py file.


In particular, VSCode has started removing a blank line between two isort-sections, don't know why.

from django...
from myproject... # removing blanck line between 2 sections
like image 874
Manu Avatar asked Sep 07 '25 17:09

Manu


1 Answers

You can make isort compatible with black and enjoy a formatted code upon saving your document. Here are two ways to achieve this:

  1. You can configure Black and Isort’s settings on pyproject.toml. Inside your root’s project folder, create/update your pyproject.toml file:
[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
line_length = 88
profile = "black"
  1. Edit settings.json and configure Black and Isort.
{
   "[python]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
       }
     },

   "python.formatting.provider": "black",
   "isort.args": ["--profile", "black"],
}

source.organizeImports: true runs Isort automatically upon saving your document.

As of version 1.85, you want to set "source.organizeImports": "explicit" to get the same functionality as the old "true", per the docs.

like image 165
xshapira Avatar answered Sep 11 '25 09:09

xshapira