Why lsp-mode prompt "command pyls is not present on the path" in emacs?

Question:

OS: Arch Linux

I follow the document and I enter pip install 'python-language-server[all]' --user in the terminal at last. After opening a python file in Emacs, lsp-mode promat me "command pyls is not present on the path" and no any completion list. But I can run it in the terminal by entering pyls. Here is my init-lsp.el.

(use-package lsp-mode
  :init (setq lsp-keymap-prefix "C-c l")
  :hook ((python-mode . lsp-deferred))
  :commands (lsp lsp-deferred))

(use-package lsp-ivy :commands lsp-ivy-workspace-symbol)
(use-package lsp-treemacs :commands lsp-treemacs-errors-list)

(provide 'init-lsp)
Asked By: Liu

||

Answers:

I seem to have solved it. Emacs cannot find the executable for pyls because the directory of this file is not in the environment variable of Emacs. Execute M-x setenv RET PATH in Emacs, and then set the environment variable. I filled in /home/liu/.local/bin

Answered By: Liu

for anyone having this issue, put the following code in your init.el

(setq lsp-pyls-server-command "<PATH-TO-PYLSP")

for example mine is

(setq lsp-pyls-server-command "/home/apollo/.local/bin/pylsp")

pyls is unmainted, so using pylsp is recomended

Answered By: Thanos_Apollo
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.