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

3

7

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

Attar answered 15/8, 2015 at 13:16 Comment(1)
This might be helpful: #35597657Rochdale
A
5

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.

Attar answered 15/8, 2015 at 15:42 Comment(5)
How did you figure this out? I finally bit the bullet to get Python installed in Vim and was nannying my head against the keyboard for a while... I'm disappointed that the 2.7 releases aren't all compatible (which defeats the purpose of the DLL anyway, doesn't it?) and also disappointed that there's no apparent documentation of what version of 2.7 (and presumably 3) are required.Gorki
It's also annoying that I need to install 32 bit Python just to grab the DLL. I use/need 64 bit for everything else.Gorki
Let me mention a side issue here: even if your Vim has a check mark for +python/dyn, the following command may screw up everything, should that directory be missing. ` let $PYTHONHOME = 'C:/Program Files/Anacoda'`. This took me days.Midmost
I suspect the problem is a bug in versions since 2.7.9. I managed to get it to work with 2.7.11 by running the following PowerShell as administrator: cd HKLM:\SOFTWARE\WOW6432Node\Python\PythonCore; mv 2.7 2.7-32.Stercoraceous
I can confirm that @Stercoraceous solution works. I am on Vim 8.0.118 and Python 2.7.11. Moving the registry item solved it for me too.Dinner
C
2

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')

Comatose answered 15/4, 2016 at 3:49 Comment(1)
pythonthreedll saved my day, thanks!Copt
C
1

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.

Cookshop answered 12/11, 2016 at 18:22 Comment(1)
Not a problem. there's an environment variable for python 3, and vim supports it!. PYTHON3_HOME. In Windows you should set it going to My computer, right click, properties, advances, click on the last bottom that is about environment variables, save everything and remember to closed vim if it's till open.Intendment

© 2022 - 2024 — McMap. All rights reserved.