Sublime Forum

How do you set ST for Python


I totally love the responsiveness and layout of ST, but I can’t seem to set it up nicely for Python. How do you go about it? Is it possible to set it up as Python IDE?

First of all I’d like to get docstring for Python functions, keywords etc when I hover over a given part of the code as you get in other code editors.
Tried Anaconda plugin, but it does not seem to do this. I’ve tried ctrl+alt+d shortcut, but it also does not work correctly - it displays only some of the doctrings (for example I can’t get docs for basic functions like “print”, but it works on “int” or user writtern functions with docs).

There are other issues with Anaconda as well - it marks async / await with syntax error and also line numbering seems to be wrong (for example it shows error on line 19, when it actually is on line 20).

So at this point Anaconda does not seem to be a working solution. Or maybe I’m doing something wrong?
Any tips on setting ST for Python?

Oh and BTW - I’ve looked. Most of the tuts are a bit old… or suggest Anaconda. But at least I was able to get a nicer code runner with Terminus.



Diagnostics, auto-completion and hover popups are provided by language servers these days.

The LSP package is a general language server client for ST. Various helper packages such as LSP-pyright help you setting up language servers for various syntaxes.

With Terminus you already have the best option to run your scripts. It can also be set-up to run them via build system.

As a code editor ST doesn’t provide a debugging interface. There are some packages attempting to provide some debugging stuff, but I don’t find them very useful.



thank you @deathaxe - that seems to be it. There’s one thing I can’t get right though - I can’t get docs for keywords (for, while, async… and so on). Any suggestions?

I’ve also managed to get similar things to happen with Anaconda - I had to point it to the python3 in the config file. But no keywords docs either.

So currently I get double entries - one from Anaconda, one from LSP. Which I expected. But I noticed another (cosmetic I’d say, but noticeable issue). Anaconda tips do not have any label sticker on the left of the given entry (k for keyword, s for snippet…), but has a short info on the right. LSP-pyright does exactly opposite.
I’ll need to check what kind of value Anaconda brings to the table actually and which packages to get for Python dev. Have to admit late night yesterday I’ve been a bit tired and tried VSCode. It was a bit easier there - installed one package (which brought 2 more with it) and actually got quite nice setup right away. But somehow I immediately missed ST - at the core I prefer its layout and the way it “feels”. So yeah, I’m not giving up :slight_smile: .



With LSP installed Anaconda is obsolete. The latter one is from pre-language-server times. It doesn’t make use of new ST4 concepts at all.

VSCode uses LSP-pylance, which is a prorietary language server derived from pyright, IIRC.

Whether docs for keywords are presented or not depends on the language-server. LSP displays anything it gets from it. If you really need docs for if and else you could probably ask for it at pyright’s Github page.



ok, so are there any tutorials on setting things up with those newer packages?
I’m a bit stuck howto make it work. I’ve been too quick in calling it success.
So I’ve installed it and its running. But I don’t think it works as it should. I get syntax hints in the popover, but not actually docs.
Can it be because on Linux I have both Python 2 and Python 3 installed (with Anaconda to get some of the docs I had to point it to Python 3)? Or does it work in totally different way?

As for keywords - I would welcome docs for them as well. I don’t need it for basic ones, but as it is meant for educational purposes that would be pretty cool. I prefer to have it - and have an option to disable it if this becomes annoying :slight_smile: .

So I guess for linting I should use Sublime Linter and appropriate package for it, right?
I hope to get this sorted so I could prepare a guide for the future, in case I need recreate such setup.

edit: and I see one option I miss from Anaconda - autoformatting to pep8. How do you achieve it in ST nowadays? I see some outdated packages that (at least according to description) won’t work well with all the extras that were added after Python 3.3.



I use the Python-black plug-in in package control for formatting:

For linting I use the SublimeLinter and the Sublime​Linter-flake​8 plug-in that works with it.

The Terminus plug-in is just magic - works great.

I haven’t installed the LSP plugins yet - next on my list.



thank you for posting this @HiroMike - I was not aware of the Python-black code formatter.
That’s one of the main challanges for me when trying to set up ST as Python IDE - finding an up to date and maintained plugins. Search and tutorials mostly point towards older and often unmaintened ones.

I think I’m slowly getting hang of it. I realized I don’t need additional linter. LSP takes care of that as well - initially I installed it for syntax suggestions and docs (still haven’t managed to get the latter working correctly though).
Atm I’m using Pyright. I’ve also installed Pylsp, but only to get formatting features (Pyright does not provide that). Have my fingers crossed for Python-black as Pyright/Pylsp combo seems a bit “wrong” :wink: .

edit: love Python-Black . So Pylsp is out. So once I figure out howto get docstrings on builtins etc, not only syntax hints I think that will be it :slight_smile:.



I have installed lsp pyright and it does autocomplete the code, but doesn’t show docstring from imported libraries, only shows docstrings for functions that I have written myself.

So which plugin to use in order to show docstring when for functions/classes?



That usually means, there is just no docstring there in the lib source/stubs. If you can provide more context such as what libs, maybe there is a solution.



Well this happens even with python core libraries as well as third party libraries like numpy

For example, hovering over python print function

The same with numpy arange for example:

However with functions I write, it displays the docstring

It seems this is the intended behavior for pyright, as per

I found pyright autocomplete way better than Anaconda plugin so I removed it, any clues how to solve this docstrings issue?



Pyright reads type and docstring information from numpy/core/multiarray.pyi for arange() function. The file however doesn’t provide docstrings.


Same applies for built-in print function. The builtin.pyi stub file shipped with pyright does not contain docstrings.

Docstrings are provided for numpy.array_str() for instance.

1 Like


Python 3.12 stdlib stubs with docstrings if you need it



Thanks for the link, but I’m new to this pyright and stub thing, so how to integrate it with sublime/pyright?



You can specify stubs path in python.analysis.extraPaths settings.



Thanks this worked!



I wonder whether each library has its stubs with docstring available as well, e.g. numpy for example



Pylance’s bundled stubs have docstrings. I don’t know where they come from though.

  • django-stubs
  • IPython-stubs
  • lxml
  • matplotlib
  • networkx
  • numpy
  • pandas
  • scipy-stubs
  • skimage
  • sklearn
  • sympy-stubs
  • transformers-stubs
  • vispy
1 Like