About the isort plugin in Sublime Text3?

1.1k Views Asked by At

purpose: Use the ST3 plugin specification python package import order

The official website query has an "isort" plugin: https://packagecontrol.io/packages/isort

But there is no description of how to use it in ST3, and the corresponding execution entry cannot be found after installation.

Question: 1. Is there a corresponding solution? 2. Are there other plugins for sorting the import order of packages?

2

There are 2 best solutions below

0
On

open your python code file in ST. ctrl+shift+p and then type "isort"

0
On

Short answer: Install isort from Sublime Text's Package Control (cmd+shift+P > install packages > search "isort") which as of time of writing points to https://github.com/asfaltboy/sublime-text-isort-plugin which contains isort 4.3.21

If the above doesn't work: The isort plugins come bundled with their own internal copy of isort and can't be adjusted to respect your system/environment isort version. I've rewritten this answer twice now in 18 months, so find the latest fork of the sublime-text-isort-plugin & install as follows:

  1. Find the latest recommended plugin from https://github.com/timothycrosley/isort/wiki/isort-Plugins
  2. Assuming this is not the plugin that Package Control links to, go to your ST3 package install directory (e.g. on macOS, Preferences -> Browse Packages).
  3. git clone https://github.com/asfaltboy/sublime-text-isort-plugin.git (replace this with the fork you'd like to use)
  4. Sublime Text should automatically detect this and shortly you should be able to see ImportSort: Sort imports when you type isort into cmd+shift+P.

It's worth using more recent versions of isort as future changes reflect various updates to the core Python code (e.g. pathlib is now in the standard library).

Reference: Timothy Crosley maintains a list of up-to-date plugins for various tools (including Kate, VIM, Emacs, Sublime, Atom, VSCode, PyCharm) on the isort wiki: https://github.com/timothycrosley/isort/wiki/isort-Plugins


Edit (June 2019): The repo at https://github.com/iham/sublime-text-isort-plugin.git no longer exists, using the repo currently located at https://github.com/jcugat/sublime-text-isort-plugin.


Edit (May 2020): The repo at https://github.com/jcugat/sublime-text-isort-plugin no longer exists, using the repo currently located at https://github.com/asfaltboy/sublime-text-isort-plugin.