lsp-pyright icon indicating copy to clipboard operation
lsp-pyright copied to clipboard

`pythonPath` wrong on MacOS

Open jdtsmith opened this issue 4 years ago • 5 comments

On MacOS, python links to the bundled Python 2.7. Since lsp-pyright searches for and configures pyright with the interpreter, this leads to real problems. There was a bug in pyright that now correctly first searches python3 in all cases, but since lsp-pyright specifically searches for and configures /usr/bin/python, it isn't solved in Emacs. See microsoft/pyright#2562.

The best solution is likely not to set the pythonPath at all. Since pyright itself expends some significant energy finding the correct interpreter on various platforms, this is duplicated effort anyway.

jdtsmith avatar Nov 19 '21 03:11 jdtsmith

I think the problem of lsp-pyright is from lsp-pyright-locate-python. It tries to find executable first from bin/python, whilst python from homebrew usually places executable (link) in /usr/local/bin/python for Python 2 and /usr/local/bin/python3 for Python 3.

Typas avatar Dec 17 '21 04:12 Typas

Right, and my point was that lsp-pyright shouldn't try to find an interpreter at all, since pyright itself will do so if it doesn't have one specifically configured (e.g. with pythonVersion = "3.9" or so).

jdtsmith avatar Dec 17 '21 04:12 jdtsmith

Argh, I just ended up directly editing the lsp-pyright.el file in the .emacs.d directory.

(defun lsp-pyright-locate-python ()
  "Look for python executable cmd to the workspace."
  (executable-find "/bin/python3"))
  ;; (or (executable-find (f-expand "bin/python" (lsp-pyright-locate-venv)))
  ;;     (with-no-warnings
  ;;       (if (>= emacs-major-version 27)
  ;;           (executable-find lsp-pyright-python-executable-cmd lsp-pyright-prefer-remote-env)
  ;;         (executable-find lsp-pyright-python-executable-cmd)))))

Did you manage to solve it in a better way?

ivan-avalos avatar Jan 07 '23 06:01 ivan-avalos

I switched to eglot.

jdtsmith avatar Jan 07 '23 11:01 jdtsmith

@ivan-avalos I created a PR to allow us to more easily configure this behavior - https://github.com/emacs-lsp/lsp-pyright/pull/89 - LMK if you think this would help solve your problem without needing to modify the source code. Hopefully it will be more robust long term

jtamagnan-delphix avatar Feb 20 '24 23:02 jtamagnan-delphix