请问怎么在Spacemacs中安装配置lsp-bridge?

本人基本是菜鸟水平,之前用lsp占用资源过于夸张。

大致看了 GitHub - manateelazycat/lsp-bridge: Fastest LSP client for Emacs的教程,由于我这github不稳定,git clone大部分失败,将lsp-bridge及相关的库下载zip后集中将el文件放到下图文件夹

然后在init.el的user-config添加了以下配置:

  "Configuration for user code:
This function is called at the very end of Spacemacs startup, after layer
configuration.
Put your configuration code here, except for variables that should be set
before packages are loaded."

  (add-to-list 'load-path "e:/lxs/.emacs.d/lisp/")
  (add-to-list 'load-path "e:/lxs/.emacs.d/lisp/lsp-bridge/")

  (require 'lsp-bridge)             ;; load lsp-bridge
  (global-corfu-mode)               ;; use corfu as completion ui
  (require 'lsp-bridge-orderless)   ;; make lsp-bridge support fuzzy match, optional
  (require 'lsp-bridge-icon)        ;; show icon for completion items, optional
  (global-lsp-bridge-mode)

  (when (display-graphic-p)
    (require 'all-the-icons))

  (use-package corfu
    ;; Optional customizations
    ;; :custom
    ;; (corfu-cycle t)                ;; Enable cycling for `corfu-next/previous'
    ;; (corfu-auto t)                 ;; Enable auto completion
    ;; (corfu-separator ?\s)          ;; Orderless field separator
    ;; (corfu-quit-at-boundary nil)   ;; Never quit at completion boundary
    ;; (corfu-quit-no-match nil)      ;; Never quit, even if there is no match
    ;; (corfu-preview-current nil)    ;; Disable current candidate preview
    ;; (corfu-preselect-first nil)    ;; Disable candidate preselection
    ;; (corfu-on-exact-match nil)     ;; Configure handling of exact matches
    ;; (corfu-echo-documentation nil) ;; Disable documentation in the echo area
    ;; (corfu-scroll-margin 5)        ;; Use scroll margin

    ;; Enable Corfu only for certain modes.
    ;; :hook ((prog-mode . corfu-mode)
    ;;        (shell-mode . corfu-mode)
    ;;        (eshell-mode . corfu-mode))

    ;; Recommended: Enable Corfu globally.
    ;; This is recommended since Dabbrev can be used globally (M-/).
    ;; See also `corfu-excluded-modes'.
    :init
    (global-corfu-mode))

  ;; A few more useful configurations...
  (use-package emacs
    :init
    ;; TAB cycle if there are only few candidates
    (setq completion-cycle-threshold 3)

    ;; Emacs 28: Hide commands in M-x which do not apply to the current mode.
    ;; Corfu commands are hidden, since they are not supposed to be used via M-x.
    ;; (setq read-extended-command-predicate
    ;;       #'command-completion-default-include-p)

    ;; Enable indentation+completion using the TAB key.
    ;; `completion-at-point' is often bound to M-TAB.
    (setq tab-always-indent 'complete))

  (require 'package)
  (add-to-list 'package-archives
               '("melpa-stable" . "https://stable.melpa.org/packages/"))
  (package-initialize)

  (use-package markdown-mode
    :ensure t
    :mode ("README\\.md\\'" . gfm-mode)
    :init (setq markdown-command "multimarkdown"))

  (use-package orderless
    :ensure t
    :custom
    (completion-styles '(orderless basic))
    (completion-category-overrides '((file (styles basic partial-completion)))))
  (require 'orderless)
  (setq completion-styles '(orderless basic)
        completion-category-overrides '((file (styles basic partial-completion))))

  (require 'posframe)

  ;; (when (posframe-workable-p)
  ;;   (posframe-show " *my-posframe-buffer*"
  ;;                  :string "This is a test"
  ;;                  :position (point)))

  ;; ;; Set before requiring evil module
  ;; (setq evil-magic 'very-magic)
  ;; (setq evil-search-module 'evil-search)
  ;; (setq evil-ex-search-vim-style-regexp t)


在此处键入或粘贴代码

可是在打开一个Python文件还是失效,而且原来的lsp也没用了

将 dotspacemacs-configuration-layers里面lsp的pylsp改成pyright也不行。


     (python :variables
             python-backend 'lsp
             ;; python-backend 'anaconda-mode
             ;; python-backend 'anaconda
             ;; python-lsp-server 'anaconda-mode
             python-lsp-server 'pyright
             ;; python-lsp-server 'pylsp
             ;; python-lsp-server 'mspyls
             ;; python-test-runner 'pytest
             ;; python-test-runner '(pytest nose)
             ;; python-formatter 'yapf
             ;; python-format-on-save t
             ;; python-save-before-test nil
             ;; python-sort-imports-on-save t
             )

请问各位大佬,应该怎么配置?

日志提示pyright-langserver.cmd不存在,确认一下你环境变量里有这个命令吗?

pip install pyright

应该是之前已经安装pyright,但还是用不了,配置了lsp-bridge,lsp还需要放在layer里吗?

您指的是e:/lxs/.spacemacs.d/.spacemacs.env文件吗?没有搜到pyright,其中PATH设置如下:

PATH=E:\lxs\Anaconda3;E:\lxs\Anaconda3\Library\mingw-w64\bin;E:\lxs\Anaconda3\Library\usr\bin;E:\lxs\Anaconda3\Library\bin;E:\lxs\Anaconda3\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;D:\Program Files\Gow\bin;E:\lxs\Git\cmd;C:\Users\Administrator\scoop\shims;E:\lxs\Anaconda3;E:\lxs\Anaconda3\Library\mingw-w64\bin;E:\lxs\Anaconda3\Library\usr\bin;E:\lxs\Anaconda3\Library\bin;E:\lxs\Anaconda3\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;D:\Program Files\Gow\bin;E:\lxs\Git\cmd;E:\lxs\texlive\2020\bin\win32;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;d:\Program Files\GNU Octave\Octave-6.2.0\;E:\lxs\linux\wsl-terminal;d:\Program Files\Tesseract-OCR;;d:\Program Files\R\R-4.1.2\bin\x64\;d:\Program Files\R\R-4.1.2\bin\;d:\Program Files\ripgrep;

完整的e:/lxs/.spacemacs.d/.spacemacs.env内容如下:

# ---------------------------------------------------------------------------
#                    Spacemacs environment variables
# ---------------------------------------------------------------------------
# This file has been generated by Spacemacs. It contains all environment
# variables defined in your default shell except those with names matching
# regexps in `spacemacs-ignored-environment-variables'. If you add any
# duplicate settings for a variable, only the first setting is effective.
# PATH is a special case: all PATH settings are read, each non-duplicate
# directory entry is prepended to the `exec-path' variable, and then PATH is
# set to the final value of `exec-path'.
#
# You can safely edit this file to change values or add or remove entries.
# Spacemacs won't overwrite the file unless you call the function
# `spacemacs/force-init-spacemacs-env'.
#
# If you don't want to use this file but would rather manage your environment
# variables yourself, remove the call to `spacemacs/load-spacemacs-env' from
# the `dotspacemacs/user-env' function in your dotfile and replace it with
# your own initialization code. You can use `exec-path-from-shell' if you add
# it to your additional packages, or simply use `setenv' and
# `(add-to-list 'exec-path ...)', which are built-in.
#
# It is recommended to use this file as it unambiguously and explicitly sets
# the values of your environment variables.
# ---------------------------------------------------------------------------

# Environment variables:
# ----------------------
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Administrator\AppData\Roaming
COMPUTERNAME=HN_LIXIAOSHENG
COMSPEC=C:\Windows\system32\cmd.exe
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramW6432=C:\Program Files\Common Files
DriverData=C:\Windows\System32\Drivers\DriverData
EM_PARENT_PROCESS_ID=12812
HOME=E:\lxs
HOMEDRIVE=C:
HOMEPATH=\Users\Administrator
LOCALAPPDATA=C:\Users\Administrator\AppData\Local
LOGONSERVER=\\HN_LIXIAOSHENG
NUMBER_OF_PROCESSORS=8
OS=Windows_NT
OneDrive=C:\Users\Administrator\OneDrive
PATH=E:\lxs\Anaconda3;E:\lxs\Anaconda3\Library\mingw-w64\bin;E:\lxs\Anaconda3\Library\usr\bin;E:\lxs\Anaconda3\Library\bin;E:\lxs\Anaconda3\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;D:\Program Files\Gow\bin;E:\lxs\Git\cmd;C:\Users\Administrator\scoop\shims;E:\lxs\Anaconda3;E:\lxs\Anaconda3\Library\mingw-w64\bin;E:\lxs\Anaconda3\Library\usr\bin;E:\lxs\Anaconda3\Library\bin;E:\lxs\Anaconda3\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;D:\Program Files\Gow\bin;E:\lxs\Git\cmd;E:\lxs\texlive\2020\bin\win32;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;d:\Program Files\GNU Octave\Octave-6.2.0\;E:\lxs\linux\wsl-terminal;d:\Program Files\Tesseract-OCR;;d:\Program Files\R\R-4.1.2\bin\x64\;d:\Program Files\R\R-4.1.2\bin\;d:\Program Files\ripgrep;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=8e0a
PROMPT=$P$G
PSModulePath=D:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
PUBLIC=C:\Users\Public
ProgramData=C:\ProgramData
ProgramFiles(x86)=D:\Program Files
ProgramFiles=D:\Program Files
ProgramW6432=D:\Program Files
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\ADMINI~1\AppData\Local\Temp
TMP=C:\Users\ADMINI~1\AppData\Local\Temp
USERDOMAIN=HN_LIXIAOSHENG
USERDOMAIN_ROAMINGPROFILE=HN_LIXIAOSHENG
USERNAME=Administrator
USERPROFILE=C:\Users\Administrator
VBOX_MSI_INSTALL_PATH=D:\Program Files\Oracle\VirtualBox\
WXDRIVE_START_ARGS=--wxdrive-setting=0 --disable-gpu --disable-software-rasterizer --enable-features=NetworkServiceInProcess
emacs_dir=e:/lxs/x86_64
windir=C:\Windows

我用的时候也碰到过这个问题。pyright 安装后启动不了。lsp-bridge 连不上 Pyright。 在终端下运行 pyright 发现,启动不了,一堆报错。

你看看这个网站(https://pypi.org/project/pyright/)的描述:

Pyright is written in TypeScript, requiring node to be installed, and is normally installed with npm. This could be an entry barrier for some Python developers as they may not have node or npm installed on their machine; I wanted to make pyright as easy to install as any normal Python package.”

我的理解是Pyright需要node.js 和 npm。 于是我就安转了下 node。 果然可以正常运行:

仅供参考 ~

1 个赞

改lsp bridge里的 lsp-bridge/langserver/ pyright_windows.json

"command": ["pyright-langserver.cmd", "--stdio"]
改为
"command": ["pyright-langserver", "--stdio"]

或者everything搜索pyright-langserver.cmd,将所在目录加入PATH环境变量里。

我又将Python的layer下变量全部注释掉了,

     (python :variables
             ;; python-backend 'lsp
             ;; python-backend 'anaconda-mode
             ;; python-backend 'anaconda
             ;; python-lsp-server 'anaconda-mode
             ;; python-lsp-server 'pyright
             ;; python-lsp-server 'pylsp
             ;; python-lsp-server 'mspyls
             ;; python-test-runner 'pytest
             ;; python-test-runner '(pytest nose)
             ;; python-formatter 'yapf
             ;; python-format-on-save t
             ;; python-save-before-test nil
             ;; python-sort-imports-on-save t
             )

并将lsp bridge里的 lsp-bridge/langserver/ pyright_windows.json

"command": ["pyright-langserver.cmd", "--stdio"]
改为
"command": ["pyright-langserver", "--stdio"]

everything搜索pyright-langserver.cmd没有找到文件。 请问现在这样是正常的吗?是不是还是用了默认的pylsp?lsp-bridge是不是没有用成功?感觉还是有点小卡顿。

我pip install node成功安装了,但还是没有实现lsp-bridge。 请问您或者哪位大佬有现成的Spacemacs配置lsp-bridge可分享吗?我用目前用Spacemacs最大的痛点就是lsp占用系统资源太大严重卡顿。

安装了还要让 Emacs 能找到。

找 pyright 的安装位置,把 bin 的路径加入 PATH。

请问pyright安装后bin位置在哪?我用everything搜了几个都没有bin文件夹。

我不熟 windows,你搜一下 pyright-langserver,它有可能在 anaconda/bin。

您好,我这里提示pyright、python-lsp-server、node 和npm都已经安装了,但直接运行pyright还是会出现和lsp-bridge一样的错误,请问是什么原因?要怎么处理?谢谢。

subprocess.CalledProcessError: Command '['e:\\lxs\\anaconda\\python.exe', '-m', 'nodeenv', 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pyright-python.Administrator\\env']' returned non-zero exit status 2.

完整的pyright::stderr信息如下:

 * Environment already exists: C:\Users\ADMINI~1\AppData\Local\Temp\pyright-python.Administrator\env
Traceback (most recent call last):
  File "e:\lxs\anaconda\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\lxs\anaconda\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "e:\lxs\anaconda\Scripts\pyright-langserver.exe\__main__.py", line 7, in <module>
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 57, in entrypoint
    sys.exit(main(*sys.argv[1:]))
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 26, in main
    return run(*args, **kwargs).returncode
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 37, in run
    version = node.latest('pyright')
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 133, in latest
    proc = run(
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 86, in run
    binary = _ensure_available(target)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 34, in _ensure_available
    return Binary(path=_ensure_node_env(target), strategy=Strategy.NODEENV)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 52, in _ensure_node_env
    _install_node_env()
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 79, in _install_node_env
    subprocess.run(args, check=True)
  File "e:\lxs\anaconda\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['e:\\lxs\\anaconda\\python.exe', '-m', 'nodeenv', 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pyright-python.Administrator\\env']' returned non-zero exit status 2.

Process pyright stderr finished
 * Environment already exists: C:\Users\ADMINI~1\AppData\Local\Temp\pyright-python.Administrator\env
Traceback (most recent call last):
  File "e:\lxs\anaconda\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\lxs\anaconda\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "e:\lxs\anaconda\Scripts\pyright-langserver.exe\__main__.py", line 7, in <module>
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 57, in entrypoint
    sys.exit(main(*sys.argv[1:]))
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 26, in main
    return run(*args, **kwargs).returncode
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 37, in run
    version = node.latest('pyright')
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 133, in latest
    proc = run(
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 86, in run
    binary = _ensure_available(target)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 34, in _ensure_available
    return Binary(path=_ensure_node_env(target), strategy=Strategy.NODEENV)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 52, in _ensure_node_env
    _install_node_env()
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 79, in _install_node_env
    subprocess.run(args, check=True)
  File "e:\lxs\anaconda\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['e:\\lxs\\anaconda\\python.exe', '-m', 'nodeenv', 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pyright-python.Administrator\\env']' returned non-zero exit status 2.

Process pyright stderr finished

安装信息如下:

Microsoft Windows [版本 10.0.17763.1098]
(c) 2018 Microsoft Corporation。保留所有权利。

e:\lxs>echo %PATH%
echo %PATH%
e:\lxs\Anaconda3;e:\lxs\Anaconda3\Library\mingw-w64\bin;e:\lxs\Anaconda3\Library\usr\bin;e:\lxs\Anaconda3\Library\bin;e:\lxs\Anaconda3\Scripts;c:\Windows\system32;c:\Windows;c:\Windows\System32\Wbem;c:\Windows\System32\WindowsPowerShell\v1.0;c:\Windows\System32\OpenSSH;c:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;c:\Program Files\Intel\Intel(R) Management Engine Components\DAL;c:\Program Files\Intel\WiFi\bin;c:\Program Files\Common Files\Intel\WirelessCommon;d:\Program Files\Gow\bin;e:\lxs\Git\cmd;c:\Users\Administrator\scoop\shims;e:\lxs\texlive\2020\bin\win32;c:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;d:\Program Files\GNU Octave\Octave-6.2.0;e:\lxs\linux\wsl-terminal;d:\Program Files\Tesseract-OCR;;d:\Program Files\R\R-4.1.2\bin\x64;d:\Program Files\R\R-4.1.2\bin;d:\Program Files\ripgrep;e:\lxs\anaconda;e:\lxs\anaconda\Library\mingw-w64\bin;e:\lxs\anaconda\Library\usr\bin;e:\lxs\anaconda\Library\bin;e:\lxs\anaconda\Scripts;d:\Program Files\Inkscape\bin;d:\Program Files\Microsoft VS Code\bin;d:\Program Files\poppler-0.68.0\bin;d:\Tencent\QQGameTempest\Hall.57734;e:\lxs\emacs-28.1\libexec\emacs\28.1\x86_64-w64-mingw32

e:\lxs>where pyright
where pyright
e:\lxs\anaconda\Scripts\pyright.exe

e:\lxs>ls e:\lxs\anaconda\Scripts\pyright*
ls e:\lxs\anaconda\Scripts\pyright*
e:\lxs\anaconda\Scripts\pyright-langserver.exe
e:\lxs\anaconda\Scripts\pyright-python-langserver.exe
e:\lxs\anaconda\Scripts\pyright-python.exe
e:\lxs\anaconda\Scripts\pyright.exe
e:\lxs\anaconda\Scripts\pyright.exe.deleteme

e:\lxs>pip install node npm
pip install node npm
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: node in .\anaconda\lib\site-packages (1.0)
Requirement already satisfied: npm in .\anaconda\lib\site-packages (0.1.1)
Requirement already satisfied: zope.deprecation in .\anaconda\lib\site-packages (from node) (4.4.0)
Requirement already satisfied: odict>=1.8.0 in .\anaconda\lib\site-packages (from node) (1.9.0)
Requirement already satisfied: zope.lifecycleevent in .\anaconda\lib\site-packages (from node) (4.4)
Requirement already satisfied: zope.deferredimport in .\anaconda\lib\site-packages (from node) (4.4)
Requirement already satisfied: zope.component in .\anaconda\lib\site-packages (from node) (5.0.1)
Requirement already satisfied: setuptools in .\anaconda\lib\site-packages (from node) (52.0.0.post20210125)
Requirement already satisfied: plumber>=1.5 in .\anaconda\lib\site-packages (from node) (1.7)
Requirement already satisfied: optional-django==0.1.0 in .\anaconda\lib\site-packages (from npm) (0.1.0)
Requirement already satisfied: zope.event in .\anaconda\lib\site-packages (from zope.component->node) (4.5.0)
Requirement already satisfied: zope.interface>=5.3.0a1 in .\anaconda\lib\site-packages (from zope.component->node) (5.3.0)
Requirement already satisfied: zope.hookable>=4.2.0 in .\anaconda\lib\site-packages (from zope.component->node) (5.1.0)
Requirement already satisfied: zope.proxy in .\anaconda\lib\site-packages (from zope.deferredimport->node) (4.5.0)

e:\lxs>pyright
pyright
 * Environment already exists: C:\Users\ADMINI~1\AppData\Local\Temp\pyright-python.Administrator\env
Traceback (most recent call last):
  File "e:\lxs\anaconda\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\lxs\anaconda\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "e:\lxs\anaconda\Scripts\pyright.exe\__main__.py", line 7, in <module>
  File "e:\lxs\anaconda\lib\site-packages\pyright\cli.py", line 72, in entrypoint
    sys.exit(main(sys.argv[1:]))
  File "e:\lxs\anaconda\lib\site-packages\pyright\cli.py", line 20, in main
    return run(*args, **kwargs).returncode
  File "e:\lxs\anaconda\lib\site-packages\pyright\cli.py", line 36, in run
    npx = node.version('npx')
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 116, in version
    proc = run(target, '--version', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 86, in run
    binary = _ensure_available(target)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 34, in _ensure_available
    return Binary(path=_ensure_node_env(target), strategy=Strategy.NODEENV)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 52, in _ensure_node_env
    _install_node_env()
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 79, in _install_node_env
    subprocess.run(args, check=True)
  File "e:\lxs\anaconda\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['e:\\lxs\\anaconda\\python.exe', '-m', 'nodeenv', 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pyright-python.Administrator\\env']' returned non-zero exit status 2.

e:\lxs>pip install pyright python-lsp-server
pip install pyright python-lsp-server
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pyright in .\anaconda\lib\site-packages (1.1.248)
Requirement already satisfied: python-lsp-server in .\anaconda\lib\site-packages (1.4.1)
Requirement already satisfied: nodeenv>=1.6.0 in .\anaconda\lib\site-packages (from pyright) (1.6.0)
Requirement already satisfied: python-lsp-jsonrpc>=1.0.0 in .\anaconda\lib\site-packages (from python-lsp-server) (1.0.0)
Requirement already satisfied: pluggy>=1.0.0 in .\anaconda\lib\site-packages (from python-lsp-server) (1.0.0)
Requirement already satisfied: ujson>=3.0.0 in .\anaconda\lib\site-packages (from python-lsp-server) (4.0.2)
Requirement already satisfied: setuptools>=39.0.0 in .\anaconda\lib\site-packages (from python-lsp-server) (52.0.0.post20210125)
Requirement already satisfied: jedi<0.19.0,>=0.17.2 in .\anaconda\lib\site-packages (from python-lsp-server) (0.17.2)
Requirement already satisfied: parso<0.8.0,>=0.7.0 in .\anaconda\lib\site-packages (from jedi<0.19.0,>=0.17.2->python-lsp-server) (0.7.1)

e:\lxs>

您好,lsp-bridge必须使用pyright吗?我在init.el中改成 python-lsp-server 'pylsp 打开Python文件不是提示启动pyright并失败。

我这里提示pyright、python-lsp-server、node 和npm都已经安装了,但直接运行pyright还是会出现和lsp-bridge一样的错误,请问是什么原因?要怎么处理?谢谢。

subprocess.CalledProcessError: Command '['e:\\lxs\\anaconda\\python.exe', '-m', 'nodeenv', 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pyright-python.Administrator\\env']' returned non-zero exit status 2.

完整的pyright::stderr信息如下:

 * Environment already exists: C:\Users\ADMINI~1\AppData\Local\Temp\pyright-python.Administrator\env
Traceback (most recent call last):
  File "e:\lxs\anaconda\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\lxs\anaconda\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "e:\lxs\anaconda\Scripts\pyright-langserver.exe\__main__.py", line 7, in <module>
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 57, in entrypoint
    sys.exit(main(*sys.argv[1:]))
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 26, in main
    return run(*args, **kwargs).returncode
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 37, in run
    version = node.latest('pyright')
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 133, in latest
    proc = run(
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 86, in run
    binary = _ensure_available(target)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 34, in _ensure_available
    return Binary(path=_ensure_node_env(target), strategy=Strategy.NODEENV)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 52, in _ensure_node_env
    _install_node_env()
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 79, in _install_node_env
    subprocess.run(args, check=True)
  File "e:\lxs\anaconda\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['e:\\lxs\\anaconda\\python.exe', '-m', 'nodeenv', 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pyright-python.Administrator\\env']' returned non-zero exit status 2.

Process pyright stderr finished
 * Environment already exists: C:\Users\ADMINI~1\AppData\Local\Temp\pyright-python.Administrator\env
Traceback (most recent call last):
  File "e:\lxs\anaconda\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\lxs\anaconda\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "e:\lxs\anaconda\Scripts\pyright-langserver.exe\__main__.py", line 7, in <module>
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 57, in entrypoint
    sys.exit(main(*sys.argv[1:]))
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 26, in main
    return run(*args, **kwargs).returncode
  File "e:\lxs\anaconda\lib\site-packages\pyright\langserver.py", line 37, in run
    version = node.latest('pyright')
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 133, in latest
    proc = run(
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 86, in run
    binary = _ensure_available(target)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 34, in _ensure_available
    return Binary(path=_ensure_node_env(target), strategy=Strategy.NODEENV)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 52, in _ensure_node_env
    _install_node_env()
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 79, in _install_node_env
    subprocess.run(args, check=True)
  File "e:\lxs\anaconda\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['e:\\lxs\\anaconda\\python.exe', '-m', 'nodeenv', 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pyright-python.Administrator\\env']' returned non-zero exit status 2.

Process pyright stderr finished

安装信息如下:

Microsoft Windows [版本 10.0.17763.1098]
(c) 2018 Microsoft Corporation。保留所有权利。

e:\lxs>echo %PATH%
echo %PATH%
e:\lxs\Anaconda3;e:\lxs\Anaconda3\Library\mingw-w64\bin;e:\lxs\Anaconda3\Library\usr\bin;e:\lxs\Anaconda3\Library\bin;e:\lxs\Anaconda3\Scripts;c:\Windows\system32;c:\Windows;c:\Windows\System32\Wbem;c:\Windows\System32\WindowsPowerShell\v1.0;c:\Windows\System32\OpenSSH;c:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;c:\Program Files\Intel\Intel(R) Management Engine Components\DAL;c:\Program Files\Intel\WiFi\bin;c:\Program Files\Common Files\Intel\WirelessCommon;d:\Program Files\Gow\bin;e:\lxs\Git\cmd;c:\Users\Administrator\scoop\shims;e:\lxs\texlive\2020\bin\win32;c:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;d:\Program Files\GNU Octave\Octave-6.2.0;e:\lxs\linux\wsl-terminal;d:\Program Files\Tesseract-OCR;;d:\Program Files\R\R-4.1.2\bin\x64;d:\Program Files\R\R-4.1.2\bin;d:\Program Files\ripgrep;e:\lxs\anaconda;e:\lxs\anaconda\Library\mingw-w64\bin;e:\lxs\anaconda\Library\usr\bin;e:\lxs\anaconda\Library\bin;e:\lxs\anaconda\Scripts;d:\Program Files\Inkscape\bin;d:\Program Files\Microsoft VS Code\bin;d:\Program Files\poppler-0.68.0\bin;d:\Tencent\QQGameTempest\Hall.57734;e:\lxs\emacs-28.1\libexec\emacs\28.1\x86_64-w64-mingw32

e:\lxs>where pyright
where pyright
e:\lxs\anaconda\Scripts\pyright.exe

e:\lxs>ls e:\lxs\anaconda\Scripts\pyright*
ls e:\lxs\anaconda\Scripts\pyright*
e:\lxs\anaconda\Scripts\pyright-langserver.exe
e:\lxs\anaconda\Scripts\pyright-python-langserver.exe
e:\lxs\anaconda\Scripts\pyright-python.exe
e:\lxs\anaconda\Scripts\pyright.exe
e:\lxs\anaconda\Scripts\pyright.exe.deleteme

e:\lxs>pip install node npm
pip install node npm
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: node in .\anaconda\lib\site-packages (1.0)
Requirement already satisfied: npm in .\anaconda\lib\site-packages (0.1.1)
Requirement already satisfied: zope.deprecation in .\anaconda\lib\site-packages (from node) (4.4.0)
Requirement already satisfied: odict>=1.8.0 in .\anaconda\lib\site-packages (from node) (1.9.0)
Requirement already satisfied: zope.lifecycleevent in .\anaconda\lib\site-packages (from node) (4.4)
Requirement already satisfied: zope.deferredimport in .\anaconda\lib\site-packages (from node) (4.4)
Requirement already satisfied: zope.component in .\anaconda\lib\site-packages (from node) (5.0.1)
Requirement already satisfied: setuptools in .\anaconda\lib\site-packages (from node) (52.0.0.post20210125)
Requirement already satisfied: plumber>=1.5 in .\anaconda\lib\site-packages (from node) (1.7)
Requirement already satisfied: optional-django==0.1.0 in .\anaconda\lib\site-packages (from npm) (0.1.0)
Requirement already satisfied: zope.event in .\anaconda\lib\site-packages (from zope.component->node) (4.5.0)
Requirement already satisfied: zope.interface>=5.3.0a1 in .\anaconda\lib\site-packages (from zope.component->node) (5.3.0)
Requirement already satisfied: zope.hookable>=4.2.0 in .\anaconda\lib\site-packages (from zope.component->node) (5.1.0)
Requirement already satisfied: zope.proxy in .\anaconda\lib\site-packages (from zope.deferredimport->node) (4.5.0)

e:\lxs>pyright
pyright
 * Environment already exists: C:\Users\ADMINI~1\AppData\Local\Temp\pyright-python.Administrator\env
Traceback (most recent call last):
  File "e:\lxs\anaconda\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\lxs\anaconda\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "e:\lxs\anaconda\Scripts\pyright.exe\__main__.py", line 7, in <module>
  File "e:\lxs\anaconda\lib\site-packages\pyright\cli.py", line 72, in entrypoint
    sys.exit(main(sys.argv[1:]))
  File "e:\lxs\anaconda\lib\site-packages\pyright\cli.py", line 20, in main
    return run(*args, **kwargs).returncode
  File "e:\lxs\anaconda\lib\site-packages\pyright\cli.py", line 36, in run
    npx = node.version('npx')
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 116, in version
    proc = run(target, '--version', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 86, in run
    binary = _ensure_available(target)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 34, in _ensure_available
    return Binary(path=_ensure_node_env(target), strategy=Strategy.NODEENV)
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 52, in _ensure_node_env
    _install_node_env()
  File "e:\lxs\anaconda\lib\site-packages\pyright\node.py", line 79, in _install_node_env
    subprocess.run(args, check=True)
  File "e:\lxs\anaconda\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['e:\\lxs\\anaconda\\python.exe', '-m', 'nodeenv', 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pyright-python.Administrator\\env']' returned non-zero exit status 2.

e:\lxs>pip install pyright python-lsp-server
pip install pyright python-lsp-server
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pyright in .\anaconda\lib\site-packages (1.1.248)
Requirement already satisfied: python-lsp-server in .\anaconda\lib\site-packages (1.4.1)
Requirement already satisfied: nodeenv>=1.6.0 in .\anaconda\lib\site-packages (from pyright) (1.6.0)
Requirement already satisfied: python-lsp-jsonrpc>=1.0.0 in .\anaconda\lib\site-packages (from python-lsp-server) (1.0.0)
Requirement already satisfied: pluggy>=1.0.0 in .\anaconda\lib\site-packages (from python-lsp-server) (1.0.0)
Requirement already satisfied: ujson>=3.0.0 in .\anaconda\lib\site-packages (from python-lsp-server) (4.0.2)
Requirement already satisfied: setuptools>=39.0.0 in .\anaconda\lib\site-packages (from python-lsp-server) (52.0.0.post20210125)
Requirement already satisfied: jedi<0.19.0,>=0.17.2 in .\anaconda\lib\site-packages (from python-lsp-server) (0.17.2)
Requirement already satisfied: parso<0.8.0,>=0.7.0 in .\anaconda\lib\site-packages (from jedi<0.19.0,>=0.17.2->python-lsp-server) (0.7.1)

e:\lxs>

楼主配置的怎么样了呢,能分享一下经验不不?

python-lsp-server应该是用来配置spacemacs的lsp的,如果你安装自己的lsp-bridge,这个变量应该是一点用都没有的。另外pyright完全没必要用anaconda装,用scoop装node然后直接npm install -g就可以。你这个用pip装实际上就是用python去调用一个脚本去自动安装一个node,然后再调用这个node,再去调用pyright,这个中间太多层了,根本不知道是哪一层出来问题。