因为虚拟环境或conda,neovim无法正确找到Python?

7
我在我的neovim中安装了YouCompleteMeUltiSnips插件。通常情况下,一切都正常。
但是我在Python开发中使用MiniCondaMiniConda类似于virtualenv,我有一个名为parser的虚拟Python环境,当我使用source activate parser激活这个虚拟环境时,出现了一些问题。
YouCompleteMe unavailable: requires Vim compiled with Python 2.x support
UltiSnips requires py >= 2.7 or py3
Press ENTER or type command to continue

所以问题在于neovim无法正确找到Python,我很困惑为什么virtualenv会影响neovim

6
通过在当前环境中使用 pip install neovim 安装(或重新安装) neovim 包,我成功解决了 UltiSnips 的错误信息。 - Alex
谢谢@Alex。那确实是答案。 - Qix - MONICA WAS MISTREATED
2个回答

3

就像 @Alex 在评论中提到的那样,pip install neovim 可以解决这个问题。


1
如果Neovim在您的$PATH中找到了Python,它会假设这是Python 2(同样的,对于python3被视为Python 3)。如果您从使用Python 3的已激活Conda环境的shell启动Neovim,则会遇到问题,因为conda env会公开一个名为python的二进制文件,但实际上是3而不是2。因此,您必须使用Neovim选项设置g:python_host_prog以指向有效的Python 2,并在其中安装所需的neovim客户端。

可能的解决方案(我已经测试过使用anaconda):

# neovim init.vim file cmd
# runs python3 for neovim from a specific env
# should resolve the need for neovim in each new python env when using nvim
# add the following to your init.vim file
let g:python3_host_prog = '/path/to/anaconda3/bin/python'

将以下内容添加到你的.vimrcginit.vim文件中(neovim GUI配置文件)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接