Repository navigation
Sort Imports not working #22147
Copy link
Copy link
Closed
Labels
bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-teamverifiedVerification succeededVerification succeeded
Milestone
Description
Type: Bug
Behaviour
Expected vs. Actual
The "Sort Imports" command in the context menu and the related command in the palette "Python Refactor: Sort Imports" should sort Python imports. However, these commands have no effect if the ms-python.isort extension is not installed as well.
The output panel contains the following message: Sort Imports: Please install and enable ms-python.isort extension to use this feature.
From a usability perspective, this behavior is not ideal. IMO, there are three solutions:
- Install the isort extension automatically with the Python extension.
- Disable the command until isort is installed
- Display an error message when running the Sort Imports command when isort is not available.
Steps to reproduce:
- From a clean Visual Studio Code environment, install the Python extension.
- Create a Python script with the following content:
import math import abc print("Hello")
- Right-click anywhere in the script and select "Sort Imports" – nothing happens.
- Run "Python Refactor: Sort Imports" from the command palette – nothing happens.
Diagnostic data
- Python version (& distribution if applicable, e.g. Anaconda): 3.11.5
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Global
- Value of the
python.languageServersetting: Default
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
2023-10-04 09:12:23.030 [info] Telemetry level is off
2023-10-04 09:12:23.030 [info] Experiments are disabled, only manually opted experiments are active.
2023-10-04 09:12:23.030 [info] Test server listening.
2023-10-04 09:12:23.030 [info] Python interpreter path: /usr/local/bin/python3
2023-10-04 09:12:23.135 [warning] Retry failed, storage update failed for key PYTHON_WORKSPACE_STORAGE_KEYS
2023-10-04 09:12:23.135 [warning] Retry failed, storage update failed for key PYTHON_WORKSPACE_STORAGE_KEYS
2023-10-04 09:12:23.483 [info] > conda info --json
2023-10-04 09:12:23.487 [info] > ~/.conda/bin/conda info --json
2023-10-04 09:12:23.491 [info] > ~/Library/r-miniconda-arm64/bin/conda info --json
2023-10-04 09:12:24.246 [info] Starting Pylance language server.
2023-10-04 09:12:38.151 [info] Telemetry level is off
2023-10-04 09:12:38.151 [info] Experiments are disabled, only manually opted experiments are active.
2023-10-04 09:12:38.198 [info] Test server listening.
2023-10-04 09:12:38.200 [info] Python interpreter path: /usr/local/bin/python3
2023-10-04 09:12:38.624 [info] > conda info --json
2023-10-04 09:12:38.641 [info] > ~/.conda/bin/conda info --json
2023-10-04 09:12:38.653 [info] > ~/Library/r-miniconda-arm64/bin/conda info --json
2023-10-04 09:12:39.390 [info] Starting Pylance language server.
2023-10-04 09:12:49.564 [info] Sort Imports: Please install and enable `ms-python.isort` extension to use this feature.
2023-10-04 09:13:37.135 [info] Sort Imports: Please install and enable `ms-python.isort` extension to use this feature.
2023-10-04 09:15:04.092 [info] Telemetry level is off
2023-10-04 09:15:04.093 [info] Experiments are disabled, only manually opted experiments are active.
2023-10-04 09:15:04.117 [info] Test server listening.
2023-10-04 09:15:04.168 [info] Python interpreter path: /usr/local/bin/python3
2023-10-04 09:15:04.562 [info] > conda info --json
2023-10-04 09:15:04.578 [info] > ~/.conda/bin/conda info --json
2023-10-04 09:15:04.583 [info] > ~/Library/r-miniconda-arm64/bin/conda info --json
2023-10-04 09:15:05.326 [info] Starting Pylance language server.
2023-10-04 09:15:40.936 [info] Sort Imports: Please install and enable `ms-python.isort` extension to use this feature.
2023-10-04 09:21:09.476 [info] Sort Imports: Please install and enable `ms-python.isort` extension to use this feature.
2023-10-04 09:21:29.030 [info] Telemetry level is off
2023-10-04 09:21:29.030 [info] Experiments are disabled, only manually opted experiments are active.
2023-10-04 09:21:29.096 [info] Test server listening.
2023-10-04 09:21:29.098 [info] Python interpreter path: /usr/local/bin/python3
2023-10-04 09:21:29.466 [info] > conda info --json
2023-10-04 09:21:29.484 [info] > ~/.conda/bin/conda info --json
2023-10-04 09:21:29.488 [info] > ~/Library/r-miniconda-arm64/bin/conda info --json
2023-10-04 09:21:30.233 [info] Starting Pylance language server.
2023-10-04 09:22:50.005 [info] Telemetry level is off
2023-10-04 09:22:50.005 [info] Experiments are disabled, only manually opted experiments are active.
2023-10-04 09:22:50.015 [info] Test server listening.
2023-10-04 09:22:50.016 [info] Python interpreter path: /usr/local/bin/python3
2023-10-04 09:22:51.194 [info] Starting Pylance language server.
2023-10-04 09:23:03.370 [info] Sort Imports: Please install and enable `ms-python.isort` extension to use this feature.
2023-10-04 09:23:06.376 [info] Sort Imports: Please install and enable `ms-python.isort` extension to use this feature.
2023-10-04 09:23:13.845 [info] Sort Imports: Please install and enable `ms-python.isort` extension to use this feature.
User Settings
languageServer: "Pylance"
testing
• pytestEnabled: true
terminal
• activateEnvironment: false
Extension version: 2023.16.0
VS Code version: Code 1.82.3 (fdb98833154679dbaa7af67a5a29fe19e55c2b73, 2023-10-02T11:09:17.749Z)
OS version: Darwin arm64 23.0.0
Modes:
System Info
| Item | Value |
|---|---|
| CPUs | Apple M2 Pro (12 x 24) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: enabled |
| Load (avg) | 1, 1, 1 |
| Memory (System) | 32.00GB (0.65GB free) |
| Process Argv | |
| Screen Reader | no |
| VM | 0% |
Metadata
Metadata
Assignees
Labels
bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-teamverifiedVerification succeededVerification succeeded
Activity
karthiknadig commentedon Oct 4, 2023
We used to do this. Most people don't use
isort, and we got feedback to remove this as an extension dependency.We will be removing this command entirely as there are more import sorting solutions now available as extensions. See,
rufffor example.extrange commentedon Oct 6, 2023
Out of curiousity what other import sorting solutions are available?
blackhas declared they will not be sorting imports, which leavesisortas the de facto import sorting tool.If that is so, then including
isortas an extension dependency might reduce the number of additional extensions to manually install/declare in adevcontainer.json.cbrnr commentedon Oct 6, 2023
ruffcan sort imports.karthiknadig commentedon Oct 6, 2023
Use this extension: https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff
/cc Charlie Marsh (@charliermarsh)
cbrnr commentedon Oct 6, 2023
Karthik Nadig (@karthiknadig) when is the removal of the command scheduled? It's a bit confusing, especially for people just starting with Python and Visual Studio Code.
karthiknadig commentedon Oct 6, 2023
This is scheduled for the october milestone.
Remove `isort` support (#22187)
01000101 commentedon Oct 17, 2023
Could someone please provide the steps to re-enable the isort functionality? Even with isort installed, the previous menu item is missing.
karthiknadig commentedon Oct 17, 2023
Joshua Cornutt (@01000101) That command will be removed. Use this instead:

starball5 commentedon Oct 18, 2023
Related on Stack Overflow: VS Code stopped resolving all python imports and Sort Imports option not available
karthiknadig commentedon Oct 23, 2023
Verification Steps: