Early notes on using the new python-lsp-server (pylsp) in GNU Emacs
When I started with LSP-based Python editing in GNU Emacs, the Python LSP server was pyls. However, pyls is apparently now unmaintained and the new replacement is python-lsp-server, also known as 'pylsp'. I noticed this recently when I looked into type hints a bit, and then when I was editing some Python today, lsp-mode or some sub-component nagged me about it:
Warning (emacs): The palantir python-language-server (pyls) is unmaintained; a maintained fork is the python-lsp-server (pylsp) project; you can install it with pip via: pip install python-lsp-server
The first thing to note about pylsp is that it supports Python 3 only (it says Python 3.6+). It works to some degree if you edit Python 2 code, but I don't fully trust it, so I'm keeping around my current Python 2 version of the older pyls. Pyls may be unmaintained, but at the moment it appears to work okay.
Because of the Python 3 versus 2 issue, I already had a front end 'pyls' script to try to figure out which Python's version of pyls I needed to run. Fortunately pyls and pylsp are currently invoked with the same (lack of) arguments, so I cheated by renaming this script to 'pylsp' and having it run the real pylsp for Python 3 and fall back to pyls for Python 2.
Lately I've been running pyls under PyPy,
so I started out by installing pylsp this way too. Pylsp (like pyls
before it) has some useful looking third party plugins and
since I was installing from scratch now I decided to install some
of them, including mypy-ls.
This is when I found out that unfortunately mypy doesn't run under
So I switched to installing pylsp using CPython with my usual '
install --user'. This worked for pylsp itself and mypy-ls,
had issues due to memestra
basically having to be installed in a virtualenv or other personal
install of CPython or PyPy. I dealt with this by removing
pyls-memestra; it might be nice but it's not essential.
(Memestra attempts to make a directory under
is owned by root if you're running the system CPython or PyPy.)
The result appears to work fine and has no more warning messages in various internal Emacs LSP buffers than I expect, but I haven't used it extensively yet. I'm not sure I'll keep mypy-ls yet, because it does add some extra warnings in some situations. The warnings are valid ones if you're using type annotations, but a potential problem if you're not. Probably it's good for me to get the warnings and maybe start fixing them.