17

I want to install a vim plugin, this plugin needs a +python feature, so when I open vim and type :version it displays -python. How can I make it enable?.

Thanks.

13

You need to compile Vim yourself or get a prebuilt Vim package that was compiled with Python support.

If you're on a Debian based system, the easiest way is to download the vim-gnome or vim-gtk package from apt (apt install vim-gtk for instance). Other distros might have a similar package with python support built in.

If you'd prefer to compile Vim yourself, download the Vim repository and pass in --enable-pythoninterp like so:

cd /tmp && git clone https://github.com/vim/vim.git && cd vim
./configure --enable-pythoninterp --prefix=/usr
make && sudo make install

On Windows, you can get the Gvim package from here which includes Python support.

6

Solution 1 :

  • Install vim-gtk package

    sudo apt install vim-gtk   
    
  • Set Vim as a default editor

    sudo update-alternatives --install /usr/bin/editor editor /usr/bin/vim.gtk 1   
    sudo update-alternatives --set editor /usr/bin/vim.gtk   
    sudo update-alternatives --install /usr/bin/vi vi /usr/bin/vim.gtk 1  
    sudo update-alternatives --set vi /usr/bin/vim.gtk   
    sudo update-alternatives --install /usr/bin/vi vim /usr/bin/vim.gtk 1  
    sudo update-alternatives --set vim /usr/bin/vim.gtk    
    

Solution 2 :

Otherwise you need to compile Vim from source code(assuming you're using Debian based system)

Prepare your system

  • Install

    sudo apt install libncurses5-dev \
    libgtk2.0-dev libatk1.0-dev \
    libcairo2-dev python-dev \
    python3-dev git
    
  • Remove Vim if you already have

    sudo apt remove vim vim-runtime gvim  
    

configure and make

cd /usr && sudo git clone https://github.com/vim/vim.git && cd vim  

sudo ./configure --with-features=huge \
--enable-multibyte \
--enable-pythoninterp=yes \
--with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu/ \  # pay attention here check directory correct
--enable-python3interp=yes \
--with-python3-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/ \  # pay attention here check directory correct
--enable-gui=gtk2 \
--enable-cscope \ 
--prefix=/usr/local/

sudo make VIMRUNTIMEDIR=/usr/local/share/vim/vim81 

Preparing deb package using checkinstall

  • And install that package

    cd /usr/vim && sudo checkinstall
    
  • Or, if want to just create a package use --install=no option with checkinstall

Set Vim as a default editor

sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/vim 1
sudo update-alternatives --set editor /usr/local/bin/vim
sudo update-alternatives --install /usr/bin/vi vi /usr/local/bin/vim 1
sudo update-alternatives --set vi /usr/local/bin/vim   

Verify that you're running the new Vim binary by looking

vim --version | grep python

Reference :
- Building Vim from Source
- checkinstall

  • 3
    Instead of linking to some deb on a random Internet site, you should rather recommend to install the official Vim from the Debian package that has +python available. I believe this should be vim-gtk – Christian Brabandt Sep 26 '18 at 14:31
  • Thanks @ChristianBrabandt for comment, I will update my answer. – finn Sep 26 '18 at 21:50
  • @ChristianBrabandt I believe the python option for the current Debian packages vim-gtk3 and vim-gtk is no longer by default included. – jacob Apr 27 at 15:57
  • @jacob you mean current debian does not include +python anymore? Could it be debian switched to python3? – Christian Brabandt Apr 27 at 16:07
4

For Windows you can always grab the very latest patched version of Vim 8.x compiled against the latest external libraries here: Vim downloads

At the time of posting the most current versions:

Latest compiled update: 2017-02-23

Vim version: 8.0.0363 Official patch log

Libraries used: Perl 5.24.1, Python 2.7.12, Python 3.6.0, Racket 6.7, Ruby 2.4.0, Lua 5.3.3, Tcl 8.6.4, and libXpm

3

You need to install a Python version on your system with the same bitness (either 32-bit or 64-bit) as your vim. Python needs to be in your PATH. If you can run it by typing python on a command prompt you should be good in this regard. Finally vim needs to be compiled to support python, but in my experience most are. Check with :version and look for python/dyn. It needs to have a plus in front of it.

2

Since this could be misinterpreted with enable the python3 feature, I consider useful mention this link for an installation according to your needs

Here are excellent guides for: *nix & windows.

Note: Pay attention to every character in the ./configure instruction and read carefully (as if you'll screw up) before doing it. And read until the end, there is no way to get lost

You should probably add this to ./configure:

--enable-fail-if-missing

Avoid to enable both python 2 & 3

Take your time This is a very very well explained procedure. Thank to Valloric

1

On Mac OS X, you can use homebrew to install first python and then vim, which vim will support python.

I use MBP, the vim support python/dyn installed by the above way, but not including python3.


# Delete wrong ans 2017.2.28 10:38AM #

  • 1
    I am not sure if I read that correctly or not, but note that in the help page, you can never see, if your Vim actually supports +python or -python. You have to look into :version – Christian Brabandt Feb 27 '17 at 15:08
  • @ChristianBrabandt you are right. Thanks for your reply. – qingchen Feb 28 '17 at 2:20
1

For a server instalation without GUI use vim-nox instead.

apt install vim-nox

1

For those using anaconda python, some additional modifications are requited. They might want to compile vim as well, especially if you want code-completion. Here is the configure command:

Modified configure command for anaconda:

 ./configure --enable-terminal --enable-gui=auto \
      --with-features=huge \
      --enable-multibyte \
       --enable-cscope --enable-terminal --enable-gui=auto  \
      --prefix=/XXX/SOFTWARE/VIM8/install3 \
   --enable-python3interp \
   --with-python3-config-dir=/XXX/anaconda2/envs/py36/bin/python3.6-config \
   --includedir=/XXX/anaconda2/envs/py36/include  \
   --includedir=/XXX/anaconda2/envs/py36/include/python3.6m \
   LDFLAGS=" -L/XXX/anaconda2/envs/py36/lib -L/XXX/anaconda2/envs/py36/lib/python3.6/config-3.6m-x86_64-linux-gnu"

Here, vim is being installed to /XXX/SOFTWARE/VIM8/install3 using anaconda environment for python 3.6 installed in /XXX/anaconda2/envs/py36

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.