Contact Us

Vim on Windows: Resolve Python dependency without a system wide installation

Reading Time: 2 min

Tags:  VimPython

Since many Vim plugins depend on Python; updating Vim often requires a Python update. We will see how to resolve such plugin dependencies using an embeddable Python distribution.

Does Python already work?

Before starting, check whether you happen to have the correct version of Python installed.

:echo has('python3')

If this prints 1 then you are good; no need to embed Python.

Was Vim compiled with Python support?

Check whether your Vim was compiled with Python support.

:version

Check for a plus sign before python3/dyn. If there is a minus sign before python3/dyn that means your Vim was not compiled with Python 3 support. You will have to install a Vim build with Python support. Vim nightly builds with Python support can be found here https://github.com/vim/vim-win32-installer. This is a repository maintained by Christian Brabandt, a major contributor to Vim. It contains both 32bit and 64bit builds of Vim. To know about other download options, please visit https://vim.fandom.com/wiki/Where_to_download_Vim

Which version of Python is needed?

The Python version is usually mentioned in the build repositories. You can also run the following command to find the Python version needed.

:py3 import sys; print(sys.version)

32-bit or 64-bit Python

For 32-bit Vim you need 32-bit Python and for 64-bit Vim you need 64-bit Python. You can use the version command to check which version of Vim you have.

Download embeddable Python

Embeddable versions of Python can be downloaded from the official site https://www.python.org/downloads/windows/.

Extract the Python zip archive in any folder of your choice. Set up Python paths in your vimrc like so:

set pythonthreehome=C:/PortableApps/python-3.6.4-embed-win32
set pythonthreedll=C:/PortableApps/python-3.6.4-embed-win32/python36.dll

Now you should be able to use Python from inside Vim.

" should print 1
echo has('python3')

" should print hello
py3 print('hello')

Share