Search code examples
pythonvim

How do I enable python in my new GVIM 8.2 installation on windows 10?


I installed the latest gvim from vim.org today. It is a 'loaded' package with many options, cfr infra (output of :version command)

I have python 2.7 installed, the python27.dll resides in c:\windows\system32. The python37.dll and pyhon39.dll are available in the 'c:\Program Files\python37' and 'c:\Program Files\python39' directories. These three directories with python dlls are on the system path.

Both Gvim and Vim output 0 on the echo has('python') and echo has('python3') commands.

Do I have to add anything in either .vimrc or .gvimrc to activate python?

Any suggestion and help would be highly appreciated!

Thanks in advance,

Guido

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Dec 15 2019 23:09:58)
MS-Windows 32-bit console version
Included patches: 1-12
Compiled by appveyor@APPVYR-WIN
Huge version without GUI.  Features included (+) or not (-):
+acl                +eval               +multi_byte_ime/dyn -tag_old_static
+arabic             +ex_extra           +multi_lang         -tag_any_white
+autocmd            +extra_search       +mzscheme/dyn       +tcl/dyn
+autochdir          -farsi              -netbeans_intg      +termguicolors
+autoservername     +file_in_path       +num64              +terminal
-balloon_eval       +find_in_path       +packages           -termresponse
+balloon_eval_term  +float              +path_extra         +textobjects
-browse             +folding            +perl/dyn           +textprop
++builtin_terms     -footer             +persistent_undo    -tgetent
+byte_offset        +gettext/dyn        +popupwin           +timers
+channel            -hangul_input       -postscript         +title
+cindent            +iconv/dyn          +printer            -toolbar
+clientserver       +insert_expand      +profile            +user_commands
+clipboard          +job                +python/dyn         +vartabs
+cmdline_compl      +jumplist           +python3/dyn        +vertsplit
+cmdline_hist       +keymap             +quickfix           +virtualedit
+cmdline_info       +lambda             +reltime            +visual
+comments           +langmap            +rightleft          +visualextra
+conceal            +libcall            +ruby/dyn           +viminfo
+cryptv             +linebreak          +scrollbind         +vreplace
+cscope             +lispindent         +signs              +vtp
+cursorbind         +listcmds           +smartindent        +wildignore
+cursorshape        +localmap           +sound              +wildmenu
+dialog_con         +lua/dyn            +spell              +windows
+diff               +menu               +startuptime        +writebackup
+digraphs           +mksession          +statusline         -xfontset
-dnd                +modify_fname       -sun_workshop       -xim
-ebcdic             +mouse              +syntax             -xpm_w32
+emacs_tags         -mouseshape         +tag_binary         -xterm_save
   system vimrc file: "$VIM\vimrc"
     user vimrc file: "$HOME\_vimrc"
 2nd user vimrc file: "$HOME\vimfiles\vimrc"
 3rd user vimrc file: "$VIM\_vimrc"
      user exrc file: "$HOME\_exrc"
  2nd user exrc file: "$VIM\_exrc"
       defaults file: "$VIMRUNTIME\defaults.vim"
Compilation: cl -c /W3 /nologo  -I. -Iproto -DHAVE_PATHDEF -DWIN32  -DFEAT_CSCOPE -DFEAT_TERMINAL -DFEAT_SOUND
-DFEAT_JOB_CHANNEL      -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 /MP -DHAVE_STDINT_H /Ox /GL
-DNDEBUG /arch:IA32 /Zl /MT -DFEAT_MBYTE_IME -DDYNAMIC_IME -DDYNAMIC_ICONV -DDYNAMIC_GETTEXT
-DFEAT_TCL -DDYNAMIC_TCL -DDYNAMIC_TCL_DLL=\"tcl86t.dll\" -DDYNAMIC_TCL_VER=\"8.6\" -DFEAT_LUA
-DDYNAMIC_LUA -DDYNAMIC_LUA_DLL=\"lua53.dll\" -DFEAT_PYTHON -DDYNAMIC_PYTHON
-DDYNAMIC_PYTHON_DLL=\"python27.dll\" -DFEAT_PYTHON3 -DDYNAMIC_PYTHON3
-DDYNAMIC_PYTHON3_DLL=\"python37.dll\" -DFEAT_MZSCHEME -I "C:\Program Files (x86)\Racket\include"
-DMZ_PRECISE_GC -DDYNAMIC_MZSCHEME -DDYNAMIC_MZSCH_DLL=\"libracket3m_a36fs8.dll\"
-DDYNAMIC_MZGC_DLL=\"libracket3m_a36fs8.dll\" -DFEAT_PERL -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS
-DDYNAMIC_PERL -DDYNAMIC_PERL_DLL=\"perl528.dll\" -DFEAT_RUBY -DDYNAMIC_RUBY -DDYNAMIC_RUBY_VER=24
-DDYNAMIC_RUBY_DLL=\"msvcrt-ruby240.dll\" -DFEAT_HUGE /Fd.\ObjCULYHTRZi386/ /Zi
Linking: link  /nologo /opt:ref /LTCG:STATUS oldnames.lib kernel32.lib advapi32.lib shell32.lib gdi32.lib
comdlg32.lib ole32.lib netapi32.lib uuid.lib /machine:i386   libcmt.lib  user32.lib  /nodefaultlib:lua53.lib
/STACK:8388608  /nodefaultlib:python27.lib /nodefaultlib:python37.lib   "C:\Tcl\lib\tclstub86.lib" winmm.lib
WSock32.lib /PDB:vim.pdb -debug

Solution

  • The usual package of Vim on Windows ships a 32-bit binary, and a 32-bit binary will not work with 64-bit libraries (which is typically what I'd expect your Python installation will be.) You need both Vim and Python to match.

    There are 64-bit versions of Vim packages available here: github.com/vim/vim-win32-installer/releases

    They're explicitly mentioned for those who want to add support for external languages such as Python.


    Once you have a 64-bit Vim binary that matches your Python libraries, you need to have it correctly find the libraries in your system.

    Try setting the 'pythonthreedll' and 'pythonthreehome' variables to point to the ones in your system.

    It can be checked the python version required by checking :version output. In particular, the compilation flags shown at the bottom will show something like -DDYNAMIC_PYTHON3_FLL=\"python37.dll\".

    Therefore, it seems Vim was built with python37.dll, so let's try that version first:

    set pythonthreedll=c:\\Program\ Files\\python37\\python37.dll
    set pythonthreehome=c:\\Program\ Files\\python37
    

    It's possible these are not exactly the paths in your system, or the values Vim wants for the settings... Please experiment with them and see if you find a combination that makes it work.

    Note that you need to escape spaces with a backslash, and you need to use two backslashes as path separators. You shouldn't have spaces elsewhere in the line (for example, around the =.)

    It's probably possible to do something similar for Python 2.7, but at this point Python 2 is basically deprecated, so I would rather spend time making Python 3 work rather than Python 2...