简体   繁体   English

运行python时GVIM崩溃了

[英]GVIM crashes when running python

I cannot use python in GVIM. 我不能在GVIM中使用python。 When I type: :python print 1 it just closes GVIM without any message. 当我输入:: :python print 1它只关闭GVIM而没有任何消息。 I triend to run it with -V90logfile but I couldn't find any information about the crash. 我试图用-V90logfile运行它,但我找不到有关崩溃的任何信息。

GVIM is compiled with python ( :version shows +python/dyn +python3/dyn ). GVIM使用python编译( :version shows +python/dyn +python3/dyn )。

GVIM version: 7.3.46 (32 bit with OLE). GVIM版本:7.3.46(带有OLE的32位)。 Python version: 2.7.3 Python版本:2.7.3

Initially GVIM couldn't find python27.dll so I edited $MYVIMRC and added: 最初GVIM找不到python27.dll所以我编辑了$MYVIMRC并添加了:

let $Path = "C:\\\\Program Files (x86)\\\\Python27;".$Path

Both GVIM and Python have been installed using corporate standards - not manually via installers. GVIM和Python都是使用企业标准安装的 - 而不是通过安装程序手动安装。 Asking here as IT were not able to help me and redirected to external support. 在这里问,因为IT无法帮助我并重定向到外部支持。

I could reproduce the error on my personal computer, where I copied both GVIM & PYTHON without installing them. 我可以在我的个人计算机上重现错误,我在那里复制了GVIM和PYTHON而没有安装它们。 Any further suggestions? 还有什么建议?

Finally solved the problem. 终于解决了这个问题。

It turned out that Python uses PYTHONPATH variable to resolve the PYTHON folder (used to load python libraries and so on). 原来,Python使用PYTHONPATH变量来解析PYTHON文件夹(用于加载python库等)。 Here is the default value for Python 2.7: 这是Python 2.7的默认值:

C:\\Python27\\Lib;C:\\Python27\\DLLs;C:\\Python27\\Lib\\lib-tk

The variable can be set using one of the following: 可以使用以下方法之一设置变量:

1. Windows registry 1. Windows注册表

Set the default value of HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Python\\PythonCore\\2.7\\PythonPath key 设置HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Python\\PythonCore\\2.7\\PythonPath键的默认值

2. Environment variable 2.环境变量

Create environment variable PYTHONPATH and set the value (same as you edit global PATH ) 创建环境变量PYTHONPATH并设置值(与编辑全局PATH相同)

3. _vimrc file 3. _vimrc文件

This is the most portable way. 这是最便携的方式。 Edit your _vimrc (ie open vim and enter :e $MYVIMRC command) and set the variable: 编辑你的_vimrc(即打开vim并输入:e $MYVIMRC命令)并设置变量:

let $PYTHONPATH = "C:\\\\Python27\\\\Lib;C:\\\\Python27\\\\DLLs;C:\\\\Python27\\\\Lib\\\\lib-tk"

Vim seems finicky about the Python DLL version. 关于Python DLL版本,Vim看起来很挑剔。 2.7.11 (the current one, as I write this) doesn't work. 2.7.11(当前的一个,正如我写的那样)不起作用。 I installed 2.7.9 per another SO answer on a similar topic and it worked fine. 我在一个类似的主题上安装了2.7.9的每个SO答案,它运行正常。

Note that the Python installer puts the DLLs into C:\\Windows\\system32 (or similar depending on language), this should be in your path automatically but in my case I just wanted Python-in-Vim to work regardless of what I had installed so I copied the 2.7.9 DLLs into the Vim installation directory. 请注意,Python安装程序将DLL放入C:\\Windows\\system32 (或类似于语言),这应该自动在您的路径中,但在我的情况下,我只是想让Python-in-Vim工作,无论我安装了什么所以我将2.7.9 DLL复制到Vim安装目录中。

Perhaps the Python virtualenv package would help here too but I have only just learned of it and not tried it. 也许Python virtualenv包也会在这里提供帮助,但我刚刚学会了它而没有尝试过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM