9

I have Windows 7 64-bit, with python 2.7.11 and python 3.5.1 (both 32-bit) installed, and I have compiled vim with python/dyn and python3/dyn, but I keep getting the following error:

:py print "hello"
E887: Sorry, this command is disabled, the Python's site module could not be loaded

However, the following all work just fine:

C:\python27\python -c "import site;"

and

:py3 print("hello")

This is my vim version info:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan 29 2016 11:58:41)
MS-Windows 32-bit console version
Included patches: 1-1194
Compiled by afontaine@PHOENIX
Huge version without GUI.  Features included (+) or not (-):
+acl                +eval               -mouseshape         +tag_old_static
+arabic             +ex_extra           +multi_byte_ime/dyn -tag_any_white
+autocmd            +extra_search       +multi_lang         -tcl
-balloon_eval       +farsi              -mzscheme           -tgetent
-browse             +file_in_path       -netbeans_intg      -termresponse
++builtin_terms     +find_in_path       +path_extra         +textobjects
+byte_offset        +float              -perl               +title
-channel            +folding            +persistent_undo    -toolbar
+cindent            -footer             -postscript         +user_commands
+clientserver       +gettext/dyn        +printer            +vertsplit
+clipboard          -hangul_input       +profile            +virtualedit
+cmdline_compl      +iconv/dyn          +python/dyn         +visual
+cmdline_hist       +insert_expand      +python3/dyn        +visualextra
+cmdline_info       +jumplist           +quickfix           +viminfo
+comments           +keymap             +reltime            +vreplace
+conceal            +langmap            +rightleft          +wildignore
+cryptv             +libcall            -ruby               +wildmenu
+cscope             +linebreak          +scrollbind         +windows
+cursorbind         +lispindent         +signs              +writebackup
+cursorshape        +listcmds           +smartindent        -xfontset
+dialog_con         +localmap           -sniff              -xim
+diff               -lua                +startuptime        -xterm_save
+digraphs           +menu               +statusline         -xpm_w32
-dnd                +mksession          -sun_workshop       
-ebcdic             +modify_fname       +syntax             
+emacs_tags         +mouse              +tag_binary
Compilation: gcc -Iproto -DWIN32 -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -DHAVE_PATHDEF -DFEAT_HUGE -DHAVE_GETTEXT -DHAVE_LOCALE_H -DDYNAMIC_GETTEXT -DFEAT_CSCOPE -DFEAT_NETBEANS_INTG -DFEAT_CHANNEL -DFEAT_GUI_W32 -DFEAT_CLIPBOARD -DFEAT_MBYTE -DFEAT_MBYTE_IME -DDYNAMIC_IME -DDYNAMIC_ICONV -pipe -w -march=i386 -Wall -DFEAT_PYTHON  -DDYNAMIC_PYTHON -DDYNAMIC_PYTHON_DLL="python27.dll" -DFEAT_PYTHON3  -DDYNAMIC_PYTHON3 -DDYNAMIC_PYTHON3_DLL="python35.dll" -DFEAT_XPM_W32 -I xpm/x86/include -I xpm/x86/../include -O3 -fomit-frame-pointer -freg-struct-return -s
Linking: gcc -Iproto -DWIN32 -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -DHAVE_PATHDEF -DFEAT_HUGE -DHAVE_GETTEXT -DHAVE_LOCALE_H -DDYNAMIC_GETTEXT -DFEAT_CSCOPE -DFEAT_NETBEANS_INTG -DFEAT_CHANNEL -DFEAT_GUI_W32 -DFEAT_CLIPBOARD -DFEAT_MBYTE -DFEAT_MBYTE_IME -DDYNAMIC_IME -DDYNAMIC_ICONV -pipe -w -march=i386 -Wall -DFEAT_PYTHON  -DDYNAMIC_PYTHON -DDYNAMIC_PYTHON_DLL="python27.dll" -DFEAT_PYTHON3  -DDYNAMIC_PYTHON3 -DDYNAMIC_PYTHON3_DLL="python35.dll" -DFEAT_XPM_W32 -I xpm/x86/include -I xpm/x86/../include -O3 -fomit-frame-pointer -freg-struct-return -s -mwindows -o gvim.exe -lkernel32 -luser32 -lgdi32 -ladvapi32 -lcomdlg32 -lcomctl32 -lversion -lwsock32 -Lxpm/x86/lib -lXpm -lole32 -luuid      

And where python27.dll outputs C:\Windows\System32

I've tried the advice from this google group post, but to no avail.

I just want to have YouCompleteMe running successfully.

4
  • :help python-dynamic says ...To use the Python interface the Python DLL must be in your search path. In a console window type "path" to see what directories are used.
    – Alex Kroll
    Feb 3, 2016 at 11:13
  • It's there. :!where python27.dll returns C:\Windows\System32\python27.dll. Also note that if the library is missing, a different error occurs: E370: Could not load library python27.dll and E263: Sorry, this command is disabled, the Python library could not be loaded.
    – afontaine
    Feb 3, 2016 at 13:41
  • Ahh. I see. :py3 works but :py won't? It's possible if one of plugin execute :py3 during vim launch. See :he python-2-and-3 for explain how python/dyn and python3/dyn works together..
    – Alex Kroll
    Feb 3, 2016 at 13:52
  • Looks like swapping out 2.7.11 for 2.7.9 did the trick. Strange though.
    – afontaine
    Feb 3, 2016 at 15:35

2 Answers 2

7

All right, apparently the state is this: VIM on Windows supports python 2.7.9, not 2.7.11. It might work with 2.7.10, I did not test it.

Even though I compiled VIM on Windows with a reference to the 2.7.11 DLL, it suddenly worked when I tried swapping out 2.7.11 for 2.7.9

I'm not sure if I did something wrong with 2.7.11, and it actually does work, but I don't have the time to figure it out.

1
3

So I had a very similar problem on my Windows 10 but for 64 bit vim and python.

TL;DR

The problem has nothing to do with YouCompleteMe in my case. Suppose YCM is complied with python 3. To make python27 completely invisible to VIM is what helps me solve the problem.

  1. I had installed TortoiseHg which has a python27.dll file and whose repository is in Path, which means it is visible to vim. To make it invisible, simply remove TortoiseHg repository from Path ( More generally, any non-python program which contains a python27.dll and whose path is in Path. By doing where python27.dll in windows console, you find all of them.)
  2. Another python27.dll in C:\Windows\System32 is also visible to vim. To make it also invisible, Move it to C:\Python27. And remove C:\Python27 from Path.
  3. Leave %PYTHONPATH% unset. Make sure Python 3.5 repository is in the Path.

My system

  • Win 10 pro 64 bit.
  • Vim 8.0.0045 64 bit huge features (+dyn/python +dyn/python3) downloaded from nightly vim windows build site.
  • YouCompleteMe complied with python 3.5.2 64 bit
  • Python 3.5.2 64 bit
  • Python 2.7.12 64 bit
  • %PYTHONHOME% is set to python 3 installation folder and included in Path.

My problem

Errors are detected when vim is launched as shown below.

Vim launch errors

Messages are

Error detected while processing function youcompleteme#Enable[5]..<SNR>124_SetUpPython:
line 39:
E887: Sorry, this command is disabled, the Python's site module could not be loaded.

Diagnostics

Both :echo has('python') and :echo has('python3') output 1. But when I do :py print 'test', vim gives me the same E887 error message.

Then I completely uninstall Python 2.7.12, but :echo has('python') still outputs 1 and :py print 'test' still gives E887 Error! Meanwhile :py3 print('test') works always OK and output test as expected.

To ensure it is not a problem from YouCompleteMe, I launched vim by gvim -u NONE. The print test gives the same error message. So problem is from vim itself, which it fails to do the staff related to python 2.7.x site module.

Some people suggest installing Python 2.7.9, but it doesn't work for me. Maybe this solution only works for 32 bit python 2.7. I didn't test so I cannot confirm.

Why all these happen:

  1. First, by doing where python27.dll I found under TortoiseHG repository there is another python27.dll file. That is why :echo has('python') still outputs 1 after I uninstalled Python 2.7.12.
  2. Then, to put it simple, the command :has('python') output 1 if both of the conditions are met:

    • Vim is compiled with +dyn/python feature (respectively +dyn/python3 when doing :has('python3'))

    • The python27.dll file is found in your Path. (respectively python35.dll. see :help-python-dynamic and :help has-python for more information.) But it doesn't do further check; that is why has-python check gives 1 but still errors are detected.

  3. Python 2.7.12 doesn't automatically set %PYTHONPATH%, while Python 3.5.2 set this value to <where_python_found>\Lib and <where_python_found>\Lib\site-packagesat Windows starup if it find python executable in Path. In my case where only python 3.5.2 installed and TortoiseHg's python27.dll is found by vim, When I run :py print 'test', vim will seek python 2.7 site module but in Python 3.5's %PYTHONPATH%. That's why Error E887 are thrown. Consequently, if we set %PYTHONPATH% explicitely to point to python 2.7, The E887 error will DISAPPEAR!

Solution

See beginning TL:DR part.

Conclusion

You once had both version of python and you uninstall one. You may happily think it's clean but vim tell you he finds the python you have deleted, you are astonished and me too. That is because often there is still some mysterious python dll left in your system and unfortunately can be detected by vim. So, Whether you conserve another version of python on your hard drive or not, make sure it is completely invisible to vim.

The fact that both version of python can be invoked by the same instance vim at run time is just all right. The real problem is both version of python shares ONE PYTHONPATH. If PYTHONPATH does not match python version, python fails to find the right site-package and make vim complain. This makes most of us think it is a vim problem. But NO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.