Compiling vim with specific version of Python

前端 未结 5 1128
感动是毒
感动是毒 2021-01-31 03:58

I\'m working on several Python projects who run on various versions of Python. I\'m hoping to set up my vim environment to use ropevim, pyflakes, and pylint but I\'ve run into s

相关标签:
5条回答
  • 2021-01-31 04:28

    I was having this same issue with 3 different versions of python on my system.

    for me the easiest thing was to change my $PATH env variable so that the folder that has the version of python I wanted was (in my case /usr/local/bin) was found before another.

    0 讨论(0)
  • 2021-01-31 04:36

    I would like to give a similar solution to crowder's that works quite well for me.

    Imagine you have Python installed in /opt/Python-2.7.5 and that the structure of that folder is

    $ tree -d -L 1 /opt/Python-2.7.5/
    /opt/Python-2.7.5/
    ├── bin
    ├── include
    ├── lib
    └── share
    

    and you would like to build vim with that version of Python. All you need to do is

    $ vi_cv_path_python=/opt/Python-2.7.5/bin/python ./configure  --enable-pythoninterp --prefix=/SOME/FOLDER
    

    Thus, just by explicitly giving vi_cv_path_python variable to configure the script will deduce everything on it's own (even the config-dir).

    This was tested multiple times on vim 7.4+ and lately with vim-7-4-324.

    0 讨论(0)
  • 2021-01-31 04:45

    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']
    
    0 讨论(0)
  • 2021-01-31 04:45

    During my compiling vim80, the system python is 2.6, I have another python 2.7 under ~/local/bin, I find that, to make the compiling work:

    1. update $PATH to place my python path ahead
    2. add a soft link, ln -s python python2 ( the configure file would try to locate python config by probing python2 )
    3. make distclean before re-run ./configure to make sure no cached wrong value is picked.
    0 讨论(0)
  • 2021-01-31 04:51

    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
    
    0 讨论(0)
提交回复
热议问题