42

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.

10 Answers 10

34

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.

3
  • Thanks. I also found this, vi.stackexchange.com/questions/10242/vim-8-0-python-support
    – Enrique GF
    Feb 24, 2017 at 3:47
  • 1
    For your own compiled packages, it should be installed under /usr/local not /usr. That may mess up package manager installed stuff. The best way to install dependencies is something like apt build-dep vim-nox
    – wbkang
    Aug 25, 2017 at 16:35
  • It seems that, these days, vim-gtk installs Python 3 (as one would hope!). I was confused when :echo has('python') was still returning 0, until I realised :echo has('python3') returned 1. Hopefully the plugin I want to use will be happy with that. (I'm running Mint 19 Cinnamon, FWIW.) Jul 17, 2020 at 21:26
11

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

4
  • 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 Sep 26, 2018 at 14:31
  • Thanks @ChristianBrabandt for comment, I will update my answer.
    – finn
    Sep 26, 2018 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, 2019 at 15:57
  • @jacob you mean current debian does not include +python anymore? Could it be debian switched to python3? Apr 27, 2019 at 16:07
7

In order to support python-mode you need to have +python AND +python3. This should get you there (at least on macOS):

./configure --prefix=/opt/local --with-features=huge --enable-pythoninterp --enable-python3interp

make

sudo make install
6

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

5

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

apt install vim-nox

4

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.

4

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

2

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 #

2
  • 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 Feb 27, 2017 at 15:08
  • @ChristianBrabandt you are right. Thanks for your reply.
    – qingchen
    Feb 28, 2017 at 2:20
2

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

2

If, like me, despite having compiled vim with python3 support, you get an error that python3 support is missing, make sure it loads the correct dll.

Check feature exists

:version
...
+python3/dyn
...

Python3 is missing during runtime

:echo has('python3')
0

Incorrect DDL used

:verbose set pythondll?
libpython2.7.so.1.0

This comment deserves the credit for suggesting this option.

Solution

Adding set pythondll=libpython3.8.so to .vimrc solved the issue by telling vim to use that dll when it needs python3. Vim's :help python-dynamic explains it

The 'pythondll' or 'pythonthreedll' option can be used to specify the Python       
shared library file instead of DYNAMIC_PYTHON_DLL or DYNAMIC_PYTHON3_DLL file      
what were specified at compile time.  The version of the shared library must       
match the Python 2.x or Python 3 version Vim was compiled with.

I couldn't find an explicit way to query what value DYNAMIC_PYTHON3_DLL was at compile time. At the time of this writing, I assumed it's the system's version.

What is python3-dynamic (python3/dyn)

For those curious, this is included in :help python-dynamic, too.

On MS-Windows and Unix the Python library can be loaded dynamically.  The :version output then includes +python/dyn or +python3/dyn.                      

This means that Vim will search for the Python DLL or shared library file only  
when needed.  When you don't use the Python interface you don't need it, thus   
you can use Vim without this file.  
1

Your Answer

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

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