1

I have a couple of plugins which use Python. They work fine on Linux but on Windows I am having difficulty in getting Python recognised.

" Language Providers
if has('unix')
  let g:python3_host_prog = '/usr/bin/python3'
elseif has('win32')
  let g:python3_host_prog = 'C:\Program Files\Python37\python.exe'
endif

That Windows location for Python is correct.

Why doesn't it work?

1
  • 1
    Are you sure Vim is compiled against Python 3.7? (version 8.2 is compiled against Python 3.6, version 9.0 is compiled against Python 3.10, the Tux version is compiled against the latest stable version currently 3.10). Oct 5, 2022 at 11:58

2 Answers 2

3

The first things to determines to make Python working are:

  • Is Python compiled for Python?
  • What is the Vim architecture (32 Bit or 64 Bit)?
  • What is the Python version that Vim expects (3.6, 3.10, ...)?

Python Support

Verifies that you have +python3/dyn among the Feature included reported by the :version command

Vim Architecture

You can determine if you are using a 32 bit or a 64 bit version of Vim by looking at the second line of the result of the :version Vim command

VIM - vi Improved 9.0 ...
MS-Windows 64-bit GUI/Console version ...
...

vs.

VIM - vi Improved 9.0 ...
MS-Windows 32-bit GUI/Console version ...
...

Python Version

Check what is the value of -DDYNAMIC_PYTHON3_DLL (from the compilation flag reported by the :version Vim Command)

  • python310.dll for Python 3.10
  • python36.dll for Python 3.6

Sanity Check

  1. Make sure you have the correct version of Python Installed (corresponding to the Vim Architecture, and Vim Dynamic Python 3 version)
  2. Make sure the corresponding Python DLL is in the path environment variable (alternatively you could make sure pythonthreedll point to the required DLL)

The following answer gives you more information about that specific point.

The the following command should echo the hello message:

:py3 print("hello")

And the following command should print you the version of python used:

:py3 import sys;print(sys.version)
2
  • 2
    I had already checked to see if Vim and Python were 64-bit, but yes, I had to update Python to 3.10 for it to work. Thanks.
    – paradroid
    Oct 5, 2022 at 18:04
  • 1
    Thanks for the feedback :-) Oct 5, 2022 at 18:07
2

Once I had the correct version of Python installed on Windows, I figured out the best way to add it to the configuration is like this, so that it does not need to be changed every time you upgrade vim/python:

if has('unix')
  let g:python3_host_prog = '/usr/bin/python3'
elseif has('win32')
  let g:python3_host_prog = (system("where python"))
endif

Your Answer

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

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