Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim for Windows: Python doesn't load properly / “crashes”

I've been struggling for 2 days to install some plugins which use python on Vim (Windows). Even with a stock vimrc.

Using the official vim 7.4 binary (x86)

  • I've checked that it comes with +python/dyn and +python3/dyn
  • I've installed Python 2.7.10 x86, and appended python's path in my Path environment.
  • :echo has('python') prints 1 as expected.
  • Yet: when I type :python print 'test', vim quits, just as if I've typed :q
  • :python mum tell me, why does windows exists?, it quits as well. Wondering why... Not a print issue at least.

Using tuxproject's nighty builds of vim 7.4.826 (x86)

  • It does come with +python/dyn and +python3/dyn. Also:

Used libraries: Perl 5.22.1, Python 2.7.10, Python 3.4.3, Ruby 2.2.3, Lua 5.3.0, Tcl 8.6.4, libXpm.

Great! That's the verison I've downloaded (2.7.10) ! Wait...

  • :echo has('python') prints 1 as expected.
  • But, "merry christmas!" says vim.

Sorry, this command is disabled, the Python's site module could not be loaded. Windows isn't good enough. Oh, and merry christmas!

Using tuxproject's nighty builds of vim 7.4.826 (x64)

I tried to use x64's python binary, taking care of removing the x86 version from my Path variable. Same issue as above.

Using Kaoriya's vim 7.4.something (x64) and Veegee's vim 7.4.803

Same issue as above.

What about compiling vim ?

Windows.


I'm not that lazy, well, yes I am... but I'll try to compile it if there isn't any other workaround. I don't really want to compile it if it won't solve anything. If only I could at least understand why these issues happen...

like image 701
D.Naesuko Avatar asked Aug 15 '15 13:08

D.Naesuko


3 Answers

All right, I managed to solve the issue.

For those who may be interested, the intended python version was Python 2.7.9 and not 2.7.10. Installing Python 2.7.9 x86 (and x64) fixed everything for the corresponding vim version.

like image 56
D.Naesuko Avatar answered Nov 08 '22 14:11

D.Naesuko


First of all, need to check for the python version compiled into the vim. One of the way is to edit the gvim executable (e.g. for window it's gvim.exe), and look for "python\d*.dll\c" as mentioned inside the vim manual. Nonetheless, when you run :echo has('python3') || has ('python'), it may give you the hint that vim cannot find and load python27.dll or python32.dll, so you can guess the python get compiled with vim in this way as well.

Once you have identified the python version needed, and if your python is installed on another location, then you can specify the pythonthreedll location to let vim to find it.

:set pythonthreedll=D:\installed\python\python35.dll

check again with following: :echo has('python3')

like image 34
ken Avatar answered Nov 08 '22 14:11

ken


I have this problem too but I didn't have to install previous versions.

All I do to solve this is just set PYTHONHOME=C:\Users\MYUSERNAME\Anaconda2 in my system environment variables! You may have to adjust the location if you did not use Anaconda as a python installer.

Note: I use python 2.7.11 and 3.5 (Both of them are installed via Anaconda 64-bit)

PS. Please ensure that PYTHONHOME is typed correctly, no underscores. And it should point to the location of Python 2 only. Don't point to Python 3 folder.

PPS. It turns out that if you set PYTHONHOME, your working python3 command on the terminal will crash, so I do not suggest this anymore.

like image 1
off99555 Avatar answered Nov 08 '22 13:11

off99555