Jedi-vim: Python interpreter for jedi in neovim

Created on 11 Nov 2016  路  8Comments  路  Source: davidhalter/jedi-vim

Issue

I use neovim and jedi to jump through my python source.
Also I use pyenv tool to manage different python executable versions.
My neovim python package is installed for python3.5 executable and neovim editor is bound to this executable as its python3_host_prog executable and jedi package is installed for system python2 executable.

" Python {{{
if filereadable(glob('~/.pyenv/versions/neovim3/bin/python'))
    let g:python3_host_prog = glob('~/.pyenv/versions/neovim3/bin/python')
endif
if filereadable(glob('~/.pyenv/versions/neovim36/bin/python'))
    let g:python3_host_prog = glob('~/.pyenv/versions/neovim36/bin/python')
endif
if filereadable(glob('~/.pyenv/versions/neovim2/bin/python'))
    let g:python_host_prog = glob('~/.pyenv/versions/neovim2/bin/python')
endif
" }}}
Output of the "JediDebugInfo" command (in a Python buffer)
Using Python version: 3
 - sys.version: 3.5.1 (default, Jun 21 2016, 19:49:53), [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]
 - site module: /Users/friday/.pyenv/versions/3.5.1/lib/python3.5/site.py
Jedi path: /Users/friday/.config/nvim/plugged/jedi-vim/jedi/jedi/__init__.py
Jedi version: 0.9.0
jedi-vim git version: e66c2e1
jedi git submodule status:  995a6531225ba0b65e1ff863d97e5404d989047b jedi (v0.9.0-19-g995a653)

When I use another python executable, jedi-vim detects the virtualenv but uses the same python executable is before.

Why python from path is not used?

Most helpful comment

I have this problem as well. The thing is, I want different Python interpreters to be used. Neovim should use whatever I have defined in g:python_host_prog (because that's the one with the neovim package installed into it). But Jedi should just use the first interpreter found in $PATH so that it can autocomplete project/local dependencies. Alternative workarounds are:

  • Install neovim into every virtualenv/pyenv and omit g:python_host_prog and g:python3_host_prog from the .vimrc to force it use whatever is first in $PATH.
  • Create a mega virtualenv that has all the dependencies of every project you have and point g:python_host_prog to that.

Alternatively use YCM or deoplete.nvim+deoplete-jedi because they work correctly.

All 8 comments

The issue is not clear to me.
g:python{3,}_host_prog is relevant for Neovim to decide on which interpreter to use.
It seems to pick up /Users/friday/.pyenv/versions/3.5.1/lib/python3.5/site.py, but you are not configuring that?
What is the setting for g:python3_host_prog?

@blueyed I want jedi to use different interpreters (the one that is in the PATH at the moment).

let g:python3_host_prog = glob('~/.pyenv/versions/neovim3/bin/python')

Here I bind my neovim editor to python 3.5.1 with neovim python package installed for it. And this interpreter is always used, no matter what interpreter is in the path.

Is it clearer now?

Not really.

I am using the following myself, and Jedi uses my virtualenv usually:

  " Arch Linux, with python-neovim packages.
  if len(glob('/usr/lib/python2*/site-packages/neovim/__init__.py', 1))
    let g:python_host_prog="/usr/bin/python2"
  endif
  if len(glob('/usr/lib/python3*/site-packages/neovim/__init__.py', 1))
    let g:python3_host_prog="/usr/bin/python3"
  endif

Maybe :JediDebugInfo should indicate that a virtualenv is/would be used?!

And this interpreter is always used, no matter what interpreter is in the path.

Do not configure it then?! The whole point of this setting is to make Neovim use this interpreter, isn't it? :)

~/.pyenv/versions/neovim3/bin/python is the interpreter for your neovim3 pyenv version, which is not the one in the path usually, except when you use it with pyenv local/shell, is it?

As for Neovim, I think it's best to let it use the system / global Python (which is easy and up-to-date with Arch Linux). That is maybe what you are trying to do with the neovim3 pyenv version?!

pyenv lets you use different interpreter versions. I've configured my neovim to use python3.5.1 by default.

let g:python3_host_prog = glob('~/.pyenv/versions/neovim3/bin/python')

But when I use python3.6.0 for example, jedi recognizes virtualenvs by does not recognize 3.6.0 interpreter. When I browse my code, it takes me to 3.5.1 stdlib sources.

How can I configure it to use the interpreter from the path (python3.6.0)?

I have this problem as well. The thing is, I want different Python interpreters to be used. Neovim should use whatever I have defined in g:python_host_prog (because that's the one with the neovim package installed into it). But Jedi should just use the first interpreter found in $PATH so that it can autocomplete project/local dependencies. Alternative workarounds are:

  • Install neovim into every virtualenv/pyenv and omit g:python_host_prog and g:python3_host_prog from the .vimrc to force it use whatever is first in $PATH.
  • Create a mega virtualenv that has all the dependencies of every project you have and point g:python_host_prog to that.

Alternatively use YCM or deoplete.nvim+deoplete-jedi because they work correctly.

@renstrom
I use deoplete + deoplete-jedi and must say they work almost perfectly.
But, I use jedi-vim's goto feature. I use different python versions for my projects, and now I've found the way to make it work.
I use exrc files, project-specific vim files. All I have to do is create a new virtualenv for a python version, install neovim package there, and redefine g:python_host_prog in project-specific .vimrc so it points to the correct python executable in this new env for this python version.

I suppose this may make your jedi-vim completion work as well.

Hi,

Did you mean you create a .vimrc which redefined g:python_host_prog in each python project?

@ttchin
That should not be necessary - except for when Jedi refuses to use the virtualenv because MAJOR.MINOR does not match.

Was this page helpful?
0 / 5 - 0 ratings