如何在 Windows 上的 gVim 中启用 Python 支持?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4718122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 17:10:52  来源:igfitidea点击:

How to enable Python support in gVim on Windows?

pythonvim

提问by wassimans

I'm trying to get Python support in gVim on Windows. Is there a way to accomplish that?

我正在尝试在 Windows 上的 gVim 中获得 Python 支持。有没有办法做到这一点?

I'm using:

我正在使用:

  • Windows XP SP3
  • gVim v. 7.3
  • Python 2.7.13 (ActivePython through Windows Installer binaries)
  • 视窗 XP SP3
  • gVim v. 7.3
  • Python 2.7.13(ActivePython 通过 Windows Installer 二进制文件)

采纳答案by David

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

通常,python 支持内置于官方 gvim 发行版中。

You will need to install python though: Python Downloads

不过你需要安装 python:Python 下载

to check if vim supports python:

检查vim是否支持python:

:echo has("python")

回答by hhafez

You will want to turn on syntax highlighting

您将要打开语法突出显示

put syntax onin your in your vimrc (the format of the vimrc file will be the same on linux/windows or any other OS)

放入syntax on你的 vimrc(vimrc 文件的格式在 linux/windows 或任何其他操作系统上是相同的)

Vim also supports autoindenting, if you want to enable auto indenting for python, have look at this guide here

Vim也支持自动缩进,如果要启用自动缩进为Python,有看这个指南在这里

The key to enable autoindenting is to include the following in vimrc

启用自动缩进的关键是在 vimrc 中包含以下内容

autocmd BufRead,BufNewFile *.py syntax on
autocmd BufRead,BufNewFile *.py set ai
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,with,try,except,finally,def,class

回答by Tuxmentat

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:

如果您通过 Windows 安装程序之一安装了 Python,则它可能是使用 Python 2.7 支持编译的。您可以通过运行来验证这一点:

:version

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

它会吐出 Vim 编译时使用的所有选项。你应该说类似的话

+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.

这意味着您支持 python 2.7 和 3.x。如果您已经有 2.5,它将无法工作。您需要升级到 2.7 或 3.x。

回答by Apreche

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.

我在 Windows 7 64 位上遇到了这个问题。我意识到我使用的是 64 位 Python 2.7.3 和 32 位 vim 7.3-46。我将两者都重新安装为 32 位版本,然后重新启动计算机。现在它起作用了。

回答by Daniel

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

我有同样的问题,但在 Windows 7 上,重新启动并没有解决它。

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.

我已经安装了 gVim 7.3。在撰写本文时,当前的 Python 版本是 3.3,所以我安装了它。但是 :has ("python") 和 :has ("python3") 仍然返回 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:
  • 如果 gVim 是 32 位的,并且它通常甚至在 64 位 Windows 上(您可以使用 :version 命令确认),那么您还需要安装 32 位 python
  • 无需重新启动 Windows 7
  • python 的版本需要匹配 gVim 编译的版本,因为它寻找特定的 DLL 名称。你可以通过 gVim 中的 :version 命令来解决这个问题,它给出了类似的东西:

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

编译: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/ /牛/ 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 / -DDYNAMIC_PERL_DLL\"

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!

所以上面告诉我,我实际上并不想要 python 3.3,我需要 3.1(或 2.7)。安装 python 3.1 后,:has ("python") 仍然返回 0,但 :has ("python3") 现在返回 1。这应该意味着基于 python 的脚本现在可以工作了!

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.

我想未来版本的 gVim 可能会针对其他版本的 python 进行编译,但是使用这种方法应该可以让您确定需要哪个版本。

回答by Brady Trainor

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.

当我输入 时:version,它显示我的 Vim 不是用 Python 编译的。也许是因为我当时没有 Python(32 位?)。

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

我确实按照建议安装了 32 位 Python,但似乎有必要重新安装 Vim。

回答by Slava

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.

对不起,迟到的贡献。问题是您不能将 x86 vim 与 x64 python 库混合使用,所有建议的解决方案归结为重新安装 x86 python。好吧,我不想重新安装 Python、Ruby 以及谁知道还有什么依赖于它们,因为 vim 没有正式在 Windows 上提供公平的 x64 发行版。好消息是你仍然可以在http://vim.wikia.com/wiki/Where_to_download_Vim找到它隐藏得很好。祝你好运,并注意 Python 库版本。

回答by GeoffreyC

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.

我有一个类似的问题。我使用 Windows XP、Python 2.7、gVim 7 多年来一直享受 vim 的全方位完成功能。最近我搬到了一台运行 Windows 8.1 的新 PC。我安装了 gVim 和我喜欢的插件,然后尝试了一切。Omni-completion 报错,说我需要用 Python 支持编译的 vim 版本。在那个阶段,我还没有安装 Python。解决方案是先安装 Python,然后重新安装 vim。全方位完成现在有效。也许安装顺序很重要。

回答by Ryan

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.

阅读以上内容后,我可以确认在 Win8.1 上安装它们的顺序很重要(对我来说至少是这样)。我安装了 32 位 VIM 7.4 几个月,然后尝试添加 Python 并且无法做到。离开 Python 2.7.9 安装并卸载/重新安装 VIM,现在它可以工作了。

回答by Light

Download the one called "OLE GUI executable"

下载一个名为“OLE GUI 可执行文件”的文件