jedi-vim找不到python2 dist-packages,但python3是

时间:2016-09-29 22:31:08

标签: python ubuntu vim jedi jedi-vim

Jedi-vim为python3 dist-packages做了自动完成,但是不能用python 2.7 dist-packages。我使用python 2运行我的程序没有问题。其他一切都正常运行。我发现vim正在运行python3。

我使用安装了python2.7和python3的 Ubuntu 16.04 ,但默认情况下使用python2.7。我已经使用pip for python2安装了jedi,并使用Bundle安装了jedi-vim。

有没有办法设置jedi-vim的路径来查找python2 dist-packages?我是否需要使用python 2编译vim?

我在.vimrc文件中添加了这一行,试图更改版本:

let g:jedi#force_py_version = 2

我收到此错误消息。

Error: jedi-vim failed to initialize Python: Could not setup g:jedi#force_py_ver
sion: jedi#setup_py_version: Vim(pyfile):E319: Sorry, the command is not availab
le in this version: pyfile /home/santi/.vim/bundle/jedi-vim/initialize.py (in fu
nction jedi#init_python[3]..<SNR>65_init_python, line 6)

将版本设置为3时工作正常。

vim --version:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 16 2016 10:50:38)
(...)
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -Wdate-time  -g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl     -L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -lpython3.5m -lpthread -ldl -lutil -lm

python(2.7):print sys.path

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/santi/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/gtk-2.0']

python3 print(sys.path)

['', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages']

的.vimrc

Plugin 'davidhalter/jedi-vim'

1 个答案:

答案 0 :(得分:0)

解决!

问题是我使用python3支持而不是python2安装了vim。我认为是Ubuntu 16.04的默认值。您可以查看:

vim --version | grep python

如果输出如下:

+cryptv          +linebreak       -python          +vreplace
+cscope          +lispindent      +python3         +wildignore

然后您可以运行这些命令来解决问题:

sudo apt install vim-gnome-py2
sudo update-alternatives --set vim /usr/bin/vim.gnome-py2
sudo update-alternatives --set gvim /usr/bin/vim.gnome-py2

再次检查python中的加号

+cryptv          +linebreak       +python          +vreplace
+cscope          +lispindent      -python3         +wildignore

那就是它。为我工作

感谢https://github.com/JBakamovic/yavide/blob/master/docs/FAQ.md