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

Mirror question to

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


Solution 1:[1]

In VS Code, the "Python" extension provides us with the following settings, which can merge specific imports from the same module into a single import statement, and organize the import statements in alphabetical order. (in "settings.json" file)

"python.sortImports.args": ["-rc", "--atomic"],

For using "Sort Imports" in VS Code, please refer to this document: Sort Imports in VS Code.

Solution 2:[2]

See my answer in How to find which isort is vscode exactly using where I describe the steps to see what is actually happening. You will see the command along with the arguments. The version of isort that is built in to the Microsoft Python plugin doesn't show as isort. Instead it is sortImports.py. It has the path so you can go look at the code for more information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jill Cheng
Solution 2 julie