10

I have Anaconda (including python3.5.2), VIM (7.4) and Jedi-VIM installed on my system. There was also a python installed on the linux system by default.

The autocompletion is working on base packages, at least. But for packages like numpy (which was included in Anaconda) the completion is not working.

By using the following command in VIM:

:py3 import sys; 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', 
'_vim_path_']

This indicates to me that the Anaconda-python interpreter and the packages are never been used by jedi-vim.

$which python
/home/user1/anaconda3/bin/python

How can I get jedi-vim to use also the path of anaconda python for getting package autocompletion?

8

I was able to fix it myself by providing jedi-vim with the location of the packages in my anaconda folder using the $PYTHONPATH variable as follows:

export PYTHONPATH=$PYTHONPATH:/home/user1/anaconda3/lib/python3.5/site-packages

Thanks to all!

Or Add following line in ~/.bash_profile

export PYTHONPATH=$PYTHONPATH:/home/user1/anaconda3/lib/python3.5/site-packages

  • Thanks! Adding export PYTHONPATH="/home/user-name/anaconda3/lib/python3.5/site-packages":$PYTHONPATH to my ~/.zshrc got jedi-vim to work correctly with anaconda. – joelostblom Sep 10 '16 at 18:22
  • 5
    You should not do that. That might lead to a SEGFAULT. It's dangerous. – Dave Halter Sep 11 '16 at 6:16
  • @DaveHalter When you said it might lead to a SEGFAULT, were you referring to what was proposed in the answer or what was proposed in the previous comment? Also, do you know why a SEGFAULT might occur? – Jack Kinsella Jun 28 at 12:46
  • 1
    @JackKinsella Python versions need to match, otherwise when compiled modules get imported you load different versions. However I have updated my answer below. There are now environments in Jedi, which make this all easily possible. – Dave Halter Jul 9 at 8:07
4

You can't. The :python and :python3 commands always use the compiled-in interpreters. If you have a recent version of Vim with python and / or python3 loaded dynamically (see :h python-dynamic) you can use pythondll and pythonthreedll to load different interpreters, but replacing CPython by Anaconda is IMO asking for segfaults (provided that Vim accepts it at all, that is).

3

2018+ Jedi Versions

You can just use :let jedi#force_py_version=3.8 if you want to switch to the latest Python version, for example. Unfortunately there is no environment listing in jedi-vim, yet. We need to build that (it is available in Jedi, though).


Old Answer

Basically the only thing you can do currently is to compile VIM with Python 3.5 support. That's probably a stupid idea, but it works.

Otherwise there will be support for cross Python versions, with https://github.com/davidhalter/jedi/issues/385.

Note that it might be possible to modify the Python PATH, but that might lead to a SEGFAULT and to other unwanted behavior, because you're basically allowing Jedi to run binary code from another Python version (Yes it actually happens).

1

You could compile vim with anaconda: I did ./configure --with-features=huge --enable-pythoninterp --with-python-config-dir=~/anaconda/lib/python2.7/config/, I remember that I did similar tests afterwards and :py import sys; print sys.path was giving me correct results.

Based on the web search you could perhaps do something like this (ex. for 3.4):

./configure --enable-python3interp --with-features=huge --with-python3-config-dir=~/anaconda/lib/python3.4/config-3.4m-x86_64-linux-gnu

1

David has a valid point about intermingling Vim with different flavors of Python and if hard coding PYTHONPATH to Anaconda Python in .profile/.bashrc really does lead to SEG 11 could one use a shell alias.

alias vim3='PYTHONPATH=/usr/lib/Anaonda/.../site-packages vim'

Perhaps this work-around will suffice.

1

I'm using 32bit vim for compatibility with other extensions, but the 64 bit python is first on my PATH for other reasons. Hence I installed the 32 bit python using conda via:

set CONDA_FORCE_32BIT=1
conda create -n py27_32bit python=2.7
activate py27_32bit
pip install jedi
deactivate

and added this to my .vimrc:

if has('win32')&& isdirectory('C:/Users/USER/AppData/Local/Continuum/anaconda2/envs/py27_32bit/')
    let $PATH = 'C:/Users/USER/AppData/Local/Continuum/anaconda2/envs/py27_32bit/;
                \C:/Users/USER/AppData/Local/Continuum/anaconda2/envs/py27_32bit/lib/;' . $PATH
    let $PYTHONPATH = 'C:/Users/USER/AppData/Local/Continuum/anaconda2/envs/py27_32bit/;
                \C:/Users/USER/AppData/Local/Continuum/anaconda2/envs/py27_32bit/DLLs/;
                \:/Users/USER/AppData/Local/Continuum/anaconda2/envs/py27_32bit/lib/;' 
endif 

where C:/Users/USER/AppData/Local/Continuum/anaconda2 is the result of calling conda info --base

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.