开发者

How to enable Python support in gVim on Windows?

开发者 https://www.devze.com 2023-02-05 17:38 出处:网络
I\'m trying to get Python support in gVim on Windows. Is开发者_JAVA技巧 there a way to accomplish that?

I'm trying to get Python support in gVim on Windows. Is开发者_JAVA技巧 there a way to accomplish that?

I'm using:

  • Windows XP SP3
  • gVim v. 7.3
  • Python 2.7.13 (ActivePython through Windows Installer binaries)


I had the same issue, but on Windows 7, and a restart didn't fix it.

I already had gVim 7.3 installed. At the time of writing the current Python version was 3.3, so I installed that. But :has ("python") and :has ("python3") still returned 0.

After much trial and error, I determined that:

  • If gVim is 32-bit, and it usually is even on 64-bit Windows (you can confirm using the :version command), then you need the 32-bit python installation as well
  • No restart of Windows 7 is required
  • The version of python needs to match the version that gVim is compiled for as it looks for a specific DLL name. You can work this out from the :version command in gVim, which gives something like:

Compilation: cl -c /W3 /nologo -I. -Iproto -DHAVE_PATHDEF -DWIN32
-DFEAT_CSCOPE -DFEAT_ NETBEANS_INTG -DFEAT_XPM_W32 -DWINVER=0x0400 -D_WIN32_WINNT=0x0400 /Fo.\ObjGOLYHTR/ / Ox /GL -DNDEBUG /Zl /MT -DFEAT_OLE -DFEAT_MBYTE_IME -DDYNAMIC_IME -DFEAT_GUI_W32 -DDYNAMI C_ICONV -DDYNAMIC_GETTEXT -DFEAT_TCL -DDYNAMIC_TCL -DDYNAMIC_TCL_DLL=\"tcl83.dll\" -DDYNAM IC_TCL_VER=\"8.3\" -DFEAT_PYTHON -DDYNAMIC_PYTHON -DDYNAMIC_PYTHON_DLL=\"python27.dll\" -D FEAT_PYTHON3 -DDYNAMIC_PYTHON3 -DDYNAMIC_PYTHON3_DLL=\"python31.dll\" -DFEAT_PERL -DDYNAMI C_PERL -DDYNAMIC_PERL_DLL=\"perl512.dll\" -DFEAT_RUBY -DDYNAMIC_RUBY -DDYNAMIC_RUBY_VER=19 1 -DDYNAMIC_RUBY_DLL=\"msvcrt-ruby191.dll\" -DFEAT_BIG /Fd.\ObjGOLYHTR/ /Zi

So the above told me that I don't actually want python 3.3, I need 3.1 (or 2.7). After installing python 3.1, :has ("python") still returns 0, but :has ("python3") now returns 1. That should mean that python based scripts will now work!

I imagine future versions of gVim may be compiled against other versions of python, but using this method should let you work out which version is required.


Usually, python support is built in the official gvim distribution.

You will need to install python though: Python Downloads

to check if vim supports python:

:echo has("python")


I encountered this problem on Windows 7 64-bit. I realized I was using 64-bit Python 2.7.3 and 32-bit vim 7.3-46. I reinstalled both as 32-bit versions and then restarted the computer. Now it works.


If you have installed Python via one of the Windows installers it is probably compiled with Python 2.7 support. You can verify this by running:

:version

It will spit out all the options Vim was compiled with. Yours should say something like

+python/dyn +python3\dyn

This means you have support for python 2.7 and 3.x. If you already have 2.5 it won't work. You will need to upgrade to either 2.7 or 3.x.


Sorry for a late contribution. The problem is that you can not mix x86 vim with x64 python libs, and all suggested solutions boil down to reinstalling x86 python. Well, I do not want to reinstall Python, Ruby and who knows what else dependent on those just because vim does not officially provide fair x64 distribution on windows. The good news is that you can still find it well hidden at http://vim.wikia.com/wiki/Where_to_download_Vim . Good luck, and take care of Python library versions.


The accepted answer didn't solve my problem, so I decide to post the solution I found after some efforts.

First, as the accepted answer pointed out, you'll need both gVim compiled with python enabled, and a corresponding python installation. Make sure they are both 32-bit or 64-bit. I found that the default build from www.vim.org didn't enable python, also it seemed to be 32-bit, which didn't match my python27. What I ended up with was the build "gvim_8.0.0003_x64.zip" from this vim Git repository

I then unzipped it, copied the "vim80" folder into the official vim installation location (created by the 32-bit installation downloaded www.vim.org).

Now vim works with my 64-bit python2.7 .

UPDATE 02/24/2017:

The procedure above failed on another machine where the local python installation is 2.7.9 . My Python version is 2.7.11 when I succeeded.

So, it seems the build from the vim Git repository works for a specific Python version. Try update your Python installation to 2.7.11 if you can. If you have to use an older version of Python, then maybe you need to build the Vim source code on your machine. It's not too hard following the instructions, and use the Visual Studio provided cmd instead of the Windows default cmd.


Add following scripts to your .vimrc

set pythonthreedll = python36.dll

Most distribution of vim in Windows is loading python dynamically, you must tell vim what the dll is, and make sure that python36.dll is in your PATH environment variable.


I had a similar problem. I've been enjoying vim's omni-completion feature for some years,using Windows XP, Python 2.7, gVim 7. Recently I moved to a new PC running Windows 8.1. I installed gVim and the plugins I like, then tried out everything. Omni-completion gave an error, saying I needed the version of vim compiled with Python support. At that stage, I had not yet installed Python. The solution was to install Python then re-install vim. Omni-conpletion now works. Perhaps the order of installation matters.


When I typed :version, it revealed that my Vim was not compiled with Python. Perhaps because I did not have Python (32-bit?) at the time.

I did install 32-bit Python as suggested, but reinstalling Vim seemed necessary.


After reading the above, I can confirm that on Win8.1 it does matter the order you install them (least for me it did). I had 32bit VIM 7.4 installed for a few months, then tried adding Python and couldn't do it. Left Python 2.7.9 installed and uninstalled/reinstalled VIM and now it works.


Download the one called "OLE GUI executable"


After trying all answers in this thread without success, the following worked for me (Win10, Python 2.7 32bit, gvim 7.4 32bit):

  1. Reinvoke the Python Installer, select Change Python
  2. Select the Option Add Python to Path, which is off by default
  3. After the installer is done, restart your machine
0

精彩评论

暂无评论...
验证码 换一张
取 消