I am at the end of hour-long research on why I cannot install vim with proper python support. Problems already recognized: Impossible to install python 2 and 3 support together on ubuntu 16.04; oh well.

After finding this gist detailing options someone got to work with pyenv and OSX, I arrived at the following parameters to compile vim, which should really work from the best of my knowledge:

Parameters: - No sudo, - no python development libraries -> get Python via pyenv seems sensible. - Installed pyenv, installed a python 2.7 in there this way: env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install -fk 2.7


export LIBRARY_PATH="$HOME/.pyenv/versions/2.7/lib:$LIBRARY_PATH"
PY_CONFIG="$HOME/.pyenv/prefix 2.7/lib/python2.7/config" # I checked that this exists
./configure                  \
    --with-features=huge                    \
    --enable-multibyte                      \
    --enable-pythoninterp=yes           \
    --with-python-config-dir=$PY_CONFIG     \
    --enable-gui=gtk2                       \
    --enable-cscope                         \
    --prefix="$HOME/.local" $@

make install

The configuration yielded i.a.

checking for python2... (cached) /usr/bin/python2
checking Python version... (cached) 2.7
checking Python is 2.3 or better... yep
checking Python's install prefix... (cached) /usr
checking Python's execution prefix... (cached) /usr
(cached) checking Python's configuration directory... (cached) /home/simon/.pyenv/versions/2.7/lib/python2.7/config
(cached) checking Python's dll name... (cached) libpython2.7.a
checking if -pthread should be used... yes
checking if compile and link flags for Python are sane... yes

Which seems okay, right?

The compiled vim --version tells me I have compiled with +python support.

But when I try to use a python-related plugin:

Error detected while processing function <SNR>78_init[14]..<SNR>78_exec_file:
line    3:
E887: Sorry, this command is disabled, the Python's site module could not be loaded.

Why god why :( Please help, thank you so much!

2 Answers 2


Okay, I have found out the error now. Turns out the configure-and-make-process had cached some information during erroneous attempts to configure the python to be linked.

make distclean was required to remove this cached information.

Is it okay to leave this question as reference for others trying to build their vim against pyenv? If not, it may be deleted.

Some notes: - Due to being on Ubuntu 16.04, I had to pick one of Python 2 and Python 3 support, i.e. one of --enable-pythoninterp and --enable-python3interp flags. See here: https://stackoverflow.com/a/23656675/2385695 - On other systems, you may able to get both, but you should be cautious; as I understood it, the dynamic linking nature can hit you back later. - The vim plugin https://github.com/lambdalisue/vim-pyenv can help you use the right pyenv version down the road for autocompletion with jedi-enabled plugins etc.


If you don't need Vim itself but can do with Neovim:

You can also try neovim. It is a (mostly) compatible fork of vim. It supports the same python interfaces from a users (or plugins) perspective but due to the internal implementation it is easier to use two versions of python simultaneously and also to use a custom python interpreter.

It can be downloaded as an appimage (no sudo required, I hope they work on ubuntu 16.04) from here.

In order to use use your virtual environment you should install the neovim pip package:

source /my/pyX/virtual/env/activate
pip install neovim

And also set the following variables in your ~/.config/neovim/init.vim file (the vimrc of neovim):

let g:python_host_prog = '/my/py2/virtual/env/bin/python'
let g:python3_host_prog = '/my/py3/virtual/env/bin/python'

Read :help python-provider for the full documentation of python in neovim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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