VS Code: Automatically Organize Python Imports

00:00
BACK TO HOME

VS Code: Automatically Organize Python Imports

10xTeam September 06, 2020 1 min read

In this quick tip, we’ll see how to configure VS Code to automatically organize Python imports upon saving your source code files.

VS Code: Automatically Organize Python Imports

You can configure VS Code to automatically sort and organize Python imports upon saving files.

First need to install the isort package system-wide using the following command:

$ pipenv install isort --dev

Open the settings using ⇧⌘P or Ctrl+Shift+P, next search for Preferences: Configure Language Specific Settings.... Press Enter and then search for Python. In the settings.json file that will be opened, add the following settings:

"[python]": {
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    }
}

Now upon saving files with the .py extension, VS Code will automatically sort and organize the imports.


Join the 10xdev Community

Subscribe and get 8+ free PDFs that contain detailed roadmaps with recommended learning periods for each programming language or field, along with links to free resources such as books, YouTube tutorials, and courses with certificates.

Audio Interrupted

We lost the audio stream. Retry with shorter sentences?