第一个问题
描述
- 在使用
pyenv
时,无法正确确定 python
版本
原因
- PATH 环境变量没有正确包含
~/.pyenv/bin
解决方法
1
| (add-to-list 'exec-path "~/.pyenv/shims")
|
- 使用
exec-path-from-shell
, 其配置
1
2
3
| (when (memq window-system '(mac ns x))
(use-package exec-path-from-shell
:init (exec-path-from-shell-initialize)))
|
第二个问题
描述
当删除全局的 python-language-server
后,使用所配置的本地环境中的 pyls
时,
总是不断重启 pyls
!
原因
emacs 没有正确读取文件夹中 .python_version
的值, 使用系统默认的版本来启动 pyls
解决方法: 安装 pyenv-mode
设置正确的当前文件夹中使用 python
的版本
1
2
| (use-package pyenv-mode-auto)
(add-hook 'python-mode-hook (lambda () (require 'pyenv-mode-auto)))
|
第三个问题
描述:
Server pyls:xxxx exited with status signal. Do you want to restart it? (y or n)
原因
由于第二个问题解决了时,=pyenv-mode-auto= 启动在 lsp
之后,故需要在第一次运行
pyls
后, 重启一下 pyls
.
解决: 更改 lsp-restart
为 'auto-start
1
| (setq-local lsp-restart 'auto-restart)
|
1
| (add-hook 'python-mode-hook (lambda () (setq-local lsp-restart 'auto-restart)))
|