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.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityYou 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.
apt build-dep vim-nox
: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
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
Otherwise you need to compile Vim from source code(assuming you're using Debian based 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
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
And install that package
cd /usr/vim && sudo checkinstall
Or, if want to just create a package use --install=no
option with checkinstall
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
vim --version | grep python
Reference :
- Building Vim from Source
- checkinstall
+python
available. I believe this should be vim-gtk
Sep 26, 2018 at 14:31
vim-gtk3
and vim-gtk
is no longer by default included.
+python
anymore? Could it be debian switched to python3?
Apr 27, 2019 at 16:07
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
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
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.
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
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 #
+python
or -python
. You have to look into :version
Feb 27, 2017 at 15:08
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:
./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
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
.
:version
...
+python3/dyn
...
:echo has('python3')
0
:verbose set pythondll?
libpython2.7.so.1.0
This comment deserves the credit for suggesting this option.
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.
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.