Bestasttung
Bestasttung

Reputation: 2458

Jedi-vim autocompletion python3.6 virtualenv not working

I've been watching some issues on the jedi-vim repo and I found that : https://github.com/davidhalter/jedi-vim/issues/704 and https://github.com/davidhalter/jedi/pull/829/files.

I tried to rename the lib in my venv to python3.5 and yes the autocompletion works, but when you run any python file it's broken (i mean i changed the name, so that's quite normal).

And for the other solutions, i can't find any files named jedi/evaluate/sys_path.py in my vundle dir.

Does anyone has an idea to make that work, i've been searching for quite a while now and can't find anything.

Thanks in advance

Upvotes: 2

Views: 2355

Answers (1)

Ahmet C. Toker
Ahmet C. Toker

Reputation: 61

I got it working with my pyenv-virtualenv, vim and jedi setup after a long hours. Hope it helps you.

First I added the jedi-vim plugin within Vundle block in ~/.vimrc file:

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
...
Plugin 'davidhalter/jedi-vim' 
call vundle#end()            

Next I added the following python3 code in ~/.vimrc to search and add packages from the pyenv/virtualenv directories individually. Unfortunately there is no activate_this.py script to do this automatically

  py3 << EOF
  import os.path
  import sys
  import vim
  import jedi
  if 'VIRTUAL_ENV' in os.environ:
      base = os.environ['VIRTUAL_ENV']
      site_packages = os.path.join(base, 'lib', 'python%s' %  sys.version[:3], 'site-packages')
      prev_sys_path = list(sys.path)
      import site
      site.addsitedir(site_packages)
      sys.real_prefix = sys.prefix
      sys.prefix = base
      # Move the added items to the front of the path:
      new_sys_path = []
      for item in list(sys.path):
          if item not in prev_sys_path:
          new_sys_path.append(item)
          sys.path.remove(item)
      sys.path[:0] = new_sys_path
   EOF

Make sure that you are able to run import jedi and import vim in your native Python. You can install them with the following commands in your terminal:

pip3 -install jedi and 
pip3 -install vim

Finally, I set the following values in my vimrc file:

set omnifunc=jedi#completions
let g:jedi#force_py_version = '3'

Make sure you switch to your pyenv environment with pyenv activate before launching vim. Only after this can the autocomplete work.

Upvotes: 3

Related Questions