reddit / emacs

I need some tips on getting python-lsp-server working with eglot:

zeta_00 · 2022-01-30 22:57
File mode specification error: (void-variable company-backends) \[jsonrpc\] Server exited with status 1 Error in post-command-hook (#\[0 "\\303\\304\\301\\242\\305#\\210\\300\\306!\\205r\\211q\\210 ?\\205\\307\\310\\311 \\")\\207" \[#<buffer [app.py](https://app.py)\> (#0) eglot--managed-mode remove-hook post-command-hook nil buffer-live-p apply eglot--connect eglot--guess-contact\] 4\]): (error "\[eglot\] -1: Server died") &#x200B; I'm pretty sure that I have all the required dependencies installed, but for some reason eglot breaks when I open a python file? Here's the python lsp that I'm using: [https://github.com/python-lsp/python-lsp-server](https://github.com/python-lsp/python-lsp-server) Any tips on how to fix this error?
sebhoagie · 2022-01-31 23:34
We need to know what is your configuration first. I use Eglot with that server and "it just works" .
zeta_00 · 2022-02-01 00:36
;;------------------------------------------------- (use-package eglot :defer t :hook (python-mode . eglot-ensure)) ;;------------------------------------------------- (use-package company :defer t :hook (python-mode . company-mode)) ;;-------------------------------------------------
zeta_00 · 2022-02-01 00:39
I use to have that just works when using the older Python language server(palantir)(it's last commit is 2020 so it's not being maintained anymore), but I installed the Python LSP Server from the above link and it's not working out-of-the-box? Is there some extra steps that are required for eglot to find this Python Language Server?
sebhoagie · 2022-02-01 01:58
Based on the config above and the error message with company backends... Try setting company to ":demand t" so it is loaded right away. If that works, you might need to play a bit with use-package to get things loaded in order.
zeta_00 · 2022-02-01 02:32
Thanks and here are the error messages that I'm getting: \[stderr\] import pkg\_resources \[stderr\] ModuleNotFoundError: No module named 'pkg\_resources' File mode specification error: (void-variable company-backends)\[jsonrpc\] Server exited with status 1Error in post-command-hook (#\[0 "\\303\\304\\301\\242\\305#\\210\\300\\306!\\205r\\211q\\210?\\205\\307\\310\\311 \\")\\207" \[#<buffer app.py> (#0) eglot--managed-mode remove-hook post-command-hook nil buffer-live-p apply eglot--connect eglot--guess-contact\] 4\]): (error "\[eglot\] -1: Server died")
zeta_00 · 2022-02-01 02:34
I installed the Python package setuptools, but I'm not sure why I'm still getting the missing pkgs\_resources error? Maybe setuptools needs to be set to a different version? I'm guessing that I'm missing a dependency, but I'm not sure. This is getting frustrating.
zeta_00 · 2022-02-01 03:16
Searching for program: No such file or directory, python-lsp-server. (add-to-list 'eglot-server-programs '(python-mode . ("python-lsp-server"))) \^ This helped me make it past the other error, but now Eglot can't seem to find the python-lsp-server, I'm not sure how to do this the nix way, because in nix the binary hash id changes. At least some progress.
-xylon · 2022-11-05 20:09
I know this is very late but: 1. The name of the program (as seen by the command line) is "pylsp" and not "python-lsp-server", so you should use the former. 2. Ensure your "pylsp" is available to emacs (e.g. if installed in a virtualenv make sure emacs is using/running that venv). I like to install these kind of transversal programs every project is going to be using (such as pylsp, black and such) with pipx so I don't have to worry about venvs.
zeta_00 · 2022-11-05 23:16
Thanks.