简体   繁体   中英

jedi-vim doesn't find python2 dist-packages, but python3 yes

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'

Solved!

The problem was that I had the vim installed with python3 support and not python2. I think is default for Ubuntu 16.04. You can checked with:

vim --version | grep python

If you output looks like this:

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

Then you can run these commands to solve the problem:

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

Check again for the plus in the python

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

That's it. Worked for me

Thanks to https://github.com/JBakamovic/yavide/blob/master/docs/FAQ.md

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM