/lsp-python-ms

emacs lsp-mode client for Microsoft's python language server

Primary LanguageEmacs LispBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

lsp-mode client leveraging Microsoft’s python-language-server.

Installation

Include lsp-python-ms in the configuration file:

(require 'lsp-python-ms)
(add-hook 'python-mode-hook #'lsp) ; or lsp-deferred

A minimal use-package initialization might be:

(use-package lsp-python-ms
  :ensure t
  :hook (python-mode . (lambda ()
                          (require 'lsp-python-ms)
                          (lsp))))  ; or lsp-deferred

Normally the python-language-server will be downloaded automatically if it doesn’t exist while opening the python scripts.

If you have troubles to download the package, you can also build the server yourselves.

  1. Install dotnet-sdk
  2. Clone and build python-language-server:
    git clone https://github.com/Microsoft/python-language-server.git
    cd python-language-server/src/LanguageServer/Impl
    dotnet publish -c Release -r osx-x64   # mac
        

    Change the -r flag according to your architecture and operating system. See Microsoft’s Runtime ID Catalog for the right value for your system.

    Then make the binary executable.

    chmod a+x $(git rev-parse --show-toplevel)/output/bin/Release/osx-x64/publish/Microsoft.Python.LanguageServer
        

    NOTE: on some systems (for example, Fedora), the executable comes out as Microsoft.Python.LanguageServer.LanguageServer.

  3. Set executable to lsp-python-ms-executable.
    ;; for executable of language server, if it's not symlinked on your PATH
    (setq lsp-python-ms-executable
          "~/python-language-server/output/bin/Release/osx-x64/publish/Microsoft.Python.LanguageServer")
        

For development, you might find it useful to run cask install.

FAQ

  1. Unresolved import warnings

    Add the directories to lsp-python-ms-extra-paths or PYTHONPATH. Refer to Troubleshooting - Unresolved import warnings.

Credit

All credit to cpbotha on vxlabs! This just tidies and packages his work there.