Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GVIM crashes when running python

Tags:

python

vim

crash

I cannot use python in GVIM. When I type: :python print 1 it just closes GVIM without any message. I triend to run it with -V90logfile but I couldn't find any information about the crash.

GVIM is compiled with python (:version shows +python/dyn +python3/dyn).

GVIM version: 7.3.46 (32 bit with OLE). Python version: 2.7.3

Initially GVIM couldn't find python27.dll so I edited $MYVIMRC and added:

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

Both GVIM and Python have been installed using corporate standards - not manually via installers. Asking here as IT were not able to help me and redirected to external support.

I could reproduce the error on my personal computer, where I copied both GVIM & PYTHON without installing them. Any further suggestions?

like image 511
frizik Avatar asked Feb 24 '16 08:02

frizik


2 Answers

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). Here is the default value for 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

Set the default value of HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\PythonPath key

2. Environment variable

Create environment variable PYTHONPATH and set the value (same as you edit global PATH)

3. _vimrc file

This is the most portable way. Edit your _vimrc (i.e. open vim and enter :e $MYVIMRC command) and set the variable:

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

like image 79
frizik Avatar answered Sep 28 '22 05:09

frizik


Vim seems finicky about the Python DLL version. 2.7.11 (the current one, as I write this) doesn't work. I installed 2.7.9 per another SO answer on a similar topic and it worked fine.

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.

Perhaps the Python virtualenv package would help here too but I have only just learned of it and not tried it.

like image 32
dash-tom-bang Avatar answered Sep 28 '22 07:09

dash-tom-bang