Compiling vim with specific version of Python

For what it's worth, and no one seems to have answered this here, I had some luck using a command line like the following:

vi_cv_path_python=/usr/bin/python26 ./configure --includedir=/usr/include/python2.6/  --prefix=/home/bcrowder/local --with-features=huge --enable-rubyinterp --enable-pythoninterp --disable-selinux --with-python-config-dir=/usr/lib64/python2.6/config

I'd recommend building vim against the 2 interpreters, then invoking it using the shell script I provided below to point it to a particular virtualenv.

I was able to build vim against Python 2.7 using the following command (2.7 is installed under $HOME/root):

% LD_LIBRARY_PATH=$HOME/root/lib PATH=$HOME/root/bin:$PATH \
    ./configure --enable-pythoninterp \ 
    --with-python-config-dir=$HOME/root/lib/python2.7/config \
    --prefix=$HOME/vim27
% make install
% $HOME/bin/vim27

:python import sys; print sys.path[:2]
['/home/pat/root/lib/python27.zip', '/home/pat/root/lib/python2.7']

Your virtualenv is actually a thin wrapper around the Python interpreter it was created with -- $HOME/foobar/lib/python2.6/config is a symlink to /usr/lib/python2.6/config.

So if you created it with the system interpreter, VIM will probe for this and ultimately link against the real interpreter, using the system sys.path by default, even though configure will show the virtualenv's path:

% PATH=$HOME/foobar/bin:$PATH ./configure --enable-pythoninterp \
    --with-python-config-dir=$HOME/foobar/lib/python2.6/config \
    --prefix=$HOME/foobar
..
checking for python... /home/pat/foobar/bin/python
checking Python's configuration directory... (cached) /home/pat/foobar/lib/python2.6/config
..

% make install
% $HOME/foobar/bin/vim
:python import sys; print sys.path[:1]
['/usr/lib/python2.6']

The workaround: Since your system vim is most likely compiled against your system python, you don't need to rebuild vim for each virtualenv: you can just drop a shell script named vim in your virtualenv's bin directory, which extends the PYTHONPATH before calling system vim:

Contents of ~/HOME/foobar/bin/vim:

#!/bin/sh
ROOT=`cd \`dirname $0\`; cd ..; pwd`
PYTHONPATH=$ROOT/lib/python2.6/site-packages /usr/bin/vim $*

When that is invoked, the virtualenv's sys.path is inserted:

% $HOME/foobar/bin/vim
:python import sys; print sys.path[:2]
['/home/pat/foobar/lib/python2.6/site-packages', '/usr/lib/python2.6']

Tags:

Python

Vim