Skip to main content
 首页 » 编程设计

python之插件无法识别 Neovim 中的 Python 主机,尽管 Python 在其中运行良好

2024年10月24日11rubylouvre

我在 Arch Linux 上使用 Neovim,安装了 python-neovim 和 python3-neovim 以支持 Python。在上次更新 neovim 的 python 客户端之前,一切都运行良好。我特别使用需要 Python 支持的 Unite 插件。

在为 neovim 安装新版本的 python 客户端后,Python 支持似乎已经中断。

echo g:loaded_python_provider 

返回 1 并且 Unite 抛出以下异常:

function <SNR>51_call_unite..unite#start..unite#start#standard..unite#init#_current_unite..remote#define#CommandBootstrap..remote#host#Require..<SNR>56_RequirePythonHost, line 15                                                              
Vim(if):Channel was closed by the client                                                                                                                                                                                                        
Error detected while processing function <SNR>51_call_unite..unite#start..unite#start#standard..unite#init#_current_unite..remote#define#CommandBootstrap..remote#host#Require..<SNR>56_RequirePythonHost:                                      
line   22:                                                                                                                                                                                                                                      
E605: Exception not caught: Failed to load python3 host. You can try to see what happened by starting Neovim with the environment variable $NVIM_PYTHON_LOG_FILE set to a file and opening the generated log file. Also, the host stderr will b 
e available in Neovim log, so it may contain useful information. See also ~/.nvimlog. 

但是,我通过尝试发现 python 在 neovim 中运行良好

:python print "Hello" 

和

:python3 print("Hello") 

我还尝试使用 python_host_prog 手动设置 python 主机。然而,这并没有改变任何东西。

更新:

与此同时,错误消息略有变化并包含 python 异常。此外,当我将 python3.4 升级到 3.5 时,我发现我的机器上存在包更新问题。一些包链接。它们在两个版本之间的链接不正确。尽管如此,完全重新安装 neovim 和 python api-bindings 也没有解决问题。

function <SNR>51_call_unite[33]..unite#start[1]..unite#start#standard[39]..unite#init#_current_unite[97]..remote#define#CommandBootstrap":                                                                           
 Zeile 5:                                                                                                                                                                                                                                     
 no request handler registered for "/home/cutuchiqueno/.vim/plugged/unite.vim/rplugin/python3/unite.py:command:UniteInitializePython"                                                                                                            
 Encountered ImportError loading plugin at /home/cutuchiqueno/.vim/plugged/unite.vim/rplugin/python3/unite.py: No module named 'unite'                                                                                                           
 Traceback (most recent call last):                                                                                                                                                                                                              
 File "/usr/lib/python3.5/site-packages/neovim/plugin/host.py", line 118, in _load                                                                                                                                                             
 file, pathname, descr = find_module(name, [directory])                                                                                                                                                                                      
 File "/usr/lib/python3.5/site-packages/neovim/compat.py", line 29, in find_module                                                                                                                                                             
 return original_find_module(fullname, path)                                                                                                                                                                                                 
 File "/usr/lib/python3.5/imp.py", line 296, in find_module                                                                                                                                                                                    
 raise ImportError(_ERR_MSG.format(name), name=name)                                                                                                                                                                                         
 ImportError: No module named 'unite' 

请您参考如下方法:

调用:UpdateRemotePlugins可以解决这个问题。由于 neovim 处理 api 通信 (msgpack-rpc) 的方式,此命令是创建特殊插件和 neovim 之间通信所需的特殊 list 文件所必需的。

从 python3.4 到 python3.5 的更新使旧的 list 文件过时了。因此,它们也必须更新。