LoginSignup
3
2

More than 3 years have passed since last update.

vim-plugでインストールしたultisnipsのエラー(UltiSnips requires py >= 2.7 or py3)を解決する

Posted at

目的

FROM centos:7で作成したコンテナで、vimをソースからインストールおよび、vim-plugでSirVer/ultisnipsをインストールしました。
vimでファイルを編集しようとしたところ、下記のようなエラーが出たので解決する。

[root@42a1c53b8591 vim]# vim test.go

UltiSnips requires py >= 2.7 or py3
Press ENTER or type command to continue

現状調査

コンテナ内は下記のような状態でした。

[root@42a1c53b8591 vim]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@42a1c53b8591 vim]# python -V
Python 2.7.5

Python2.7以上入っているのに何故???

いろいろ調べているうちに、vimがPythonを使えるようにするためには、ただPythonがインストールされているだけでは駄目なようでした。
実際にvimがPythonを使えるかどうかは、versionから確認できるようです。

[root@42a1c53b8591 vim]# vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 28 2019 20:51:19)
Included patches: 1-1223
Compiled by root@26a8c32821ad
Huge version without GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     -tag_old_static
+arabic            -farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    -tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
-balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
-browse            +fork()            -mzscheme          +textobjects
++builtin_terms    -gettext           +netbeans_intg     +textprop
+byte_offset       -hangul_input      +num64             +timers
+channel           +iconv             +packages          +title
+cindent           +insert_expand     +path_extra        -toolbar
-clientserver      +job               -perl              +user_commands
-clipboard         +jumplist          +persistent_undo   +vartabs
+cmdline_compl     +keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      +langmap           +profile           +visual
+comments          +libcall           -python            +visualextra
+conceal           +linebreak         -python3           +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
+cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          +rightleft         +wildmenu
+cursorshape       -lua               -ruby              +windows
+dialog_con        +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             -X11
+digraphs          +modify_fname      +smartindent       -xfontset
-dnd               +mouse             +startuptime       -xim
-ebcdic            -mouseshape        +statusline        -xpm
+emacs_tags        +mouse_dec         -sun_workshop      -xsmp
+eval              -mouse_gpm         +syntax            -xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save
   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: "/usr/local/share/vim"
Compilation: gcc -std=gnu99 -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -std=gnu99   -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -ldl

上記が、オプションも何も指定せずに、ソースコードからコンパイル、インストールしたvimの状態です。
実際に-python-python3と、-(マイナス)が付いており、使えない状態です。

解決に向けて

じゃあどうすればよいかというと、configureでPythonを有効化してあげれば良いようです。

[root@3306435929d9 vim]# ./configure --help | grep python
  --enable-pythoninterp=OPTS   Include Python interpreter. default=no OPTS=no/yes/dynamic
  --enable-python3interp=OPTS  Include Python3 interpreter. default=no OPTS=no/yes/dynamic
  --with-python-command=NAME  name of the Python 2 command (default: python2 or python)
  --with-python-config-dir=PATH  Python's config directory (deprecated)
  --with-python3-command=NAME  name of the Python 3 command (default: python3 or python)
  --with-python3-config-dir=PATH  Python's config directory (deprecated)
[root@42a1c53b8591 vim]# 
[root@42a1c53b8591 vim]# ./configure --enable-pythoninterp=yes
~省略~
[root@42a1c53b8591 vim]# make
~省略~
[root@42a1c53b8591 vim]# make install
~省略~
[root@42a1c53b8591 vim]# vim --version | grep python
+comments          +libcall           -python            +visualextra
+conceal           +linebreak         -python3           +viminfo

うまくいかない。。。
そこで、インストールされているPythonパッケージを確かめてみると、python-develが入っていないことがわかりました。
python-develをインストールして、vimを再インストールしました。

[root@3306435929d9 vim]# yum list installed | grep python
dbus-python.x86_64                        1.1.1-9.el7                   @CentOS
libxml2-python.x86_64                     2.9.1-6.el7_2.3               @CentOS
python.x86_64                             2.7.5-77.el7_6                @updates
python-chardet.noarch                     2.2.1-1.el7_1                 @CentOS
python-gobject-base.x86_64                3.22.0-1.el7_4.1              @CentOS
python-iniparse.noarch                    0.4-9.el7                     @CentOS
python-kitchen.noarch                     1.1.1-5.el7                   @CentOS
python-libs.x86_64                        2.7.5-77.el7_6                @updates
python-pycurl.x86_64                      7.19.0-19.el7                 @CentOS
python-urlgrabber.noarch                  3.10-9.el7                    @CentOS
rpm-python.x86_64                         4.11.3-35.el7                 @CentOS
[root@3306435929d9 vim]# yum -y install python-devel
~省略~
[root@42a1c53b8591 vim]# ./configure --enable-pythoninterp=yes
~省略~
[root@42a1c53b8591 vim]# make
~省略~
[root@42a1c53b8591 vim]# make install
~省略~

その結果、ようやく+pythonとなり、無事vim実行時のエラーが消えました。

[root@3306435929d9 vim]# vim --version | grep python
+comments          +libcall           +python            +visualextra
+conceal           +linebreak         -python3           +viminfo
Linking: gcc -std=gnu99   -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lnsl   -ldl    -L/usr/lib64/pytho
2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic

参考

vim に python用プラグイン導入 [CentOS 7.4] - Qiita
./configure --help

最後に

vimをソースからインストールすることがほぼ無く、妙なところに引っかかってしまいました。
help見れば一瞬でわかったのに。。。:weary:

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2