I'm having real trouble getting Python 3 working inside vim. I've downloaded the latest 8.0 source from the vim github, and I've been configuring it with this, using the Anaconda distribution including Python 3.6:
./configure \
--with-features=huge \
--enable-multibyte \
--enable-cscope \
--enable-multibyte \
--enable-python3interp=yes \
--with-features=huge \
--with-python3-config-dir=$ANACONDA_PATH/lib/python3.6/config-3.6m-x86_64-linux-gnu \
--enable-fail-if-missing \
--prefix=$LOCAL_BIN
Make the usual way (make -j), install, then run, test Python 3 inclusion with:
:python3 import sys
And then I get a SIGABRT killing vim. I added the Vundle klen/python-mode, which kills vim on startup with:
Fatal Python error: PyThreadState_Get: no current thread
I've seen a bunch of people have had this error using YCM on OS X with MacPorts / system bundled versions of Python getting confused. That doesn't seem to be the case here, I'm running a Debian machine running 3.16 kernel, checking vim --version shows that python3 is correctly compiled in, and it points to the correct areas for the python3.6 library (no conflict in /usr/local/lib):
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Aug 19 2017 11:46:55)
Included patches: 1-966
Compiled by Matt
Huge version without GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_sgr +tag_old_static
+arabic +find_in_path -mouse_sysmouse -tag_any_white
+autocmd +float +mouse_urxvt -tcl
-balloon_eval +folding +mouse_xterm +termguicolors
-browse -footer +multi_byte -terminal
++builtin_terms +fork() +multi_lang +terminfo
+byte_offset +gettext -mzscheme +termresponse
+channel -hangul_input +netbeans_intg +textobjects
+cindent +iconv +num64 +timers
+clientserver +insert_expand +packages +title
+clipboard +job +path_extra -toolbar
+cmdline_compl +jumplist -perl +user_commands
+cmdline_hist +keymap +persistent_undo +vertsplit
+cmdline_info +lambda +postscript +virtualedit
+comments +langmap +printer +visual
+conceal +libcall +profile +visualextra
+cryptv +linebreak -python +viminfo
+cscope +lispindent +python3 +vreplace
+cursorbind +listcmds +quickfix +wildignore
+cursorshape +localmap +reltime +wildmenu
+dialog_con -lua +rightleft +windows
+diff +menu -ruby +writebackup
+digraphs +mksession +scrollbind +X11
-dnd +modify_fname +signs +xfontset
-ebcdic +mouse +smartindent -xim
+emacs_tags -mouseshape +startuptime -xpm
+eval +mouse_dec +statusline +xsmp_interact
+ex_extra -mouse_gpm -sun_workshop +xterm_clipboard
+extra_search -mouse_jsbterm +syntax -xterm_save
+farsi +mouse_netterm +tag_binary
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/home/matt/.local/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -Wl,--as-needed -o vim -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lnsl -ldl -L/home/matt/anaconda3/lib/python3.6/config-3.6m-x86_64-linux-gnu -lpython3.6m -lpthread -ldl -lutil -lrt -lm
I also ran this compiled instance through gdb, and info shared shows that the correct libpython3.6 is loaded from my anaconda directory. I'm really lost by this. Can anyone think of something I'm missing?
解决方案
So I was dealing with same problem today, and I managed to fix it by configuring the VIM compilation with
--enable-python3interp=dynamic
I found the advice at https://github.com/Valloric/YouCompleteMe/issues/2855. On my site, I didn't even need to meddle with LD_LIBRARY_PATH or similar.