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'
  • You can switch the Python interpreter. Read the jedi-vim's README. – Dave Halter Oct 01 '16 at 11:03
  • @DaveHalter: I have the same problem with my Ubuntu 16.10 installation. The same error message when I have the line `let g:jedi#force_py_version = 2` in my .vimrc, and the same error when I do `:call jedi#force_py_version(2)`. If I replace 2 with 3 in those commands though there is no error. – krumpelstiltskin Oct 25 '16 at 09:22
  • Maybe add an issue to the jedi-vim tracker? I have not implemented that part and I feel like this is either a bug or your installation is wrong (and therefore I think stackoverflow is probably not the right place to figure this out). – Dave Halter Oct 25 '16 at 13:28

1 Answers1

0

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