3

Jedi-vim does autocompletion for python3 dist-packages, but can't fnd python 2.7 dist-packages. I run my program using python 2 without problem. Everything else runs correctly. I found out that vim is running with python3.

I'm using Ubuntu 16.04 that comes with both python2.7 and python3 installed, but uses python2.7 by default. I've installed jedi with pip for python2, and jedi-vim with Bundle.

Is there a way to set the path of jedi-vim to look for python2 dist-packages? Do I need to compile vim using python 2 instead?

I added this line in my .vimrc file trying to change the version:

let g:jedi#force_py_version = 2

And I got this error message.

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)

Works fine when settings the version to 3 though.

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'
4

1 回答 1

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

于 2017-02-21T03:41:44.563 回答