vim-tw / ama

Helping vimmer in Taiwan with any questions.
https://github.com/vim-tw/ama/issues
16 stars 1 forks source link

YouCompleteMe unavailable: No module named future on Ubuntu 16.04 #16

Closed racterub closed 8 years ago

racterub commented 8 years ago

我在裝 vim Vundle 時,YCM 會噴 error 給我。

請問一下要怎麼解決?

我的 vim 是從 source 裝的,不是從 apt 載下來。

" powerline
set rtp+=usr/local/lib/python2.7/dist-packages/powerline/bindings/vim
python from powerline.vim import setup as powerline_setup
python powerline_setup()
python del powerline_setup

" http://www.erikzaadi.com/2012/03/19/auto-installing-vundle-from-your-vimrc/
" Setting up Vundle - the vim plugin bundler
let iCanHazVundle=1
let vundle_readme=expand('~/.vim/bundle/vundle/README.md')
if !filereadable(vundle_readme)
  echo "Installing Vundle.."
  echo ""
  silent !mkdir -p ~/.vim/bundle
  silent !git clone https://github.com/gmarik/vundle ~/.vim/bundle/vundle
  let iCanHazVundle=0
endif

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'

" My Bundles here:"
Bundle 'Lokaltog/vim-easymotion'
Bundle 'Lokaltog/vim-powerline'
Bundle 'airblade/vim-gitgutter'
Bundle "MarcWeber/vim-addon-mw-utils"
Bundle "tomtom/tlib_vim"
Bundle 'Townk/vim-autoclose'
Bundle 'kien/ctrlp.vim'
Bundle 'scrooloose/nerdtree'
let NERDTreeMinimalUI=1
let NERDTreeWinSize=25
Bundle 'majutsushi/tagbar'
Bundle 'tomtom/tcomment_vim'
Bundle 'tpope/vim-fugitive'
Bundle 'honza/vim-snippets'
Bundle 'garbas/vim-snipmate'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'L9'
Bundle 'FuzzyFinder'
Bundle 'Valloric/YouCompleteMe'
Plugin 'sheerun/vim-wombat-scheme'

"Press F1 to open NERDTree
map <F1> :NERDTreeToggle<CR>
call vundle#end()            " required
filetype plugin indent on    " required

"map vim record mode to none
map q <Nop>
scriptencoding utf-8
set encoding=utf-8    
set langmenu=en_US.UTF-8
language message en_US.UTF-8

" Vim settings and mappings
" You can edit them as you wish

" Configuration file for vim
set modelines=0     " CVE-2007-2438
set backspace=2     " more powerful backspacing
set nocompatible    " not compatible with the old-fashion vi mode
set autoindent      " enable autoindent
set nocompatible    " no vi-compatible

" allow plugins by file type (required for plugins!)
filetype plugin on
filetype indent on

" general
set wildmenu
set smarttab
set showmatch       " Cursor shows matching ) and }
set showmode        " Show current mode  "
set cursorline      " cursorline highlighting
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set nu              " show line numbers
set ru              " ruler
set laststatus=2 
set ls=2            " always show status bar
set incsearch       " incremental search
set hlsearch        " highlighted search results
set autoread        " auto read when file is changed from outside "
set history=1000    " keep 50 lines of command line history  "
set scrolloff=3     " when scrolling, keep cursor 3 lines away from screen border
syntax on           " syntax highlight on

"Youcompleteme fix
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'

" tab length exceptions on some file types
autocmd FileType html setlocal shiftwidth=4 tabstop=4 softtabstop=4
autocmd FileType htmldjango setlocal shiftwidth=4 tabstop=4 softtabstop=4
autocmd FileType javascript setlocal shiftwidth=4 tabstop=4 softtabstop=4

" tab navigation mappings
map tn :tabn<CR>
map tp :tabp<CR>
map tm :tabm 
map tt :tabnew 
map ts :tab split<CR>
map <C-S-Right> :tabn<CR>
imap <C-S-Right> <ESC>:tabn<CR>
map <C-S-Left> :tabp<CR>
imap <C-S-Left> <ESC>:tabp<CR>

" navigate windows with meta+arrows
map <M-Right> <c-w>l
map <M-Left> <c-w>h
map <M-Up> <c-w>k
map <M-Down> <c-w>j
imap <M-Right> <ESC><c-w>l
imap <M-Left> <ESC><c-w>h
imap <M-Up> <ESC><c-w>k
imap <M-Down> <ESC><c-w>j

" old autocomplete keyboard shortcut
imap <C-J> <C-X><C-O>

" Comment this line to enable autocompletion preview window
" (displays documentation related to the selected completion option)
" Disabled by default because preview makes the window flicker
set completeopt-=preview

" save as sudo
ca w!! w !sudo tee "%"

" simple recursive grep
nmap ,r :Ack 
nmap ,wr :Ack <cword><CR>

" use 256 colors when possible
if (&term =~? 'mlterm\|xterm\|xterm-256\|screen-256') || has('nvim')
        let &t_Co = 256
    colorscheme wombat

" colors for gvim
if has('gui_running')
    colorscheme wombat
endif

" autocompletion of files and commands behaves like shell
" (complete only the common part, list the options that match)
set wildmode=list:longest

" ============================================================================
" Plugins settings and mappings
" Edit them as you wish.

" Tagbar ----------------------------- 

" toggle tagbar display
map <F4> :TagbarToggle<CR>
" autofocus on tagbar open
let g:tagbar_autofocus = 1

" NERDTree ----------------------------- 

" toggle nerdtree display
map <F3> :NERDTreeToggle<CR>
" open nerdtree with the current file selected
nmap ,t :NERDTreeFind<CR>
" don;t show these file types
let NERDTreeIgnore = ['\.pyc$', '\.pyo$']

" Tasklist ------------------------------

" show pending tasks list
map <F2> :TaskList<CR>

" CtrlP ------------------------------

" file finder mapping
let g:ctrlp_map = ',e'
" tags (symbols) in current file finder mapping
nmap ,g :CtrlPBufTag<CR>
" tags (symbols) in all files finder mapping
nmap ,G :CtrlPBufTagAll<CR>
" general code finder in all files mapping
nmap ,f :CtrlPLine<CR>
" recent files finder mapping
nmap ,m :CtrlPMRUFiles<CR>
" commands finder mapping
nmap ,c :CtrlPCmdPalette<CR>
" to be able to call CtrlP with default search text
function! CtrlPWithSearchText(search_text, ctrlp_command_end)
    execute ':CtrlP' . a:ctrlp_command_end
    call feedkeys(a:search_text)
endfunction
" same as previous mappings, but calling with current word as default text
nmap ,wg :call CtrlPWithSearchText(expand('<cword>'), 'BufTag')<CR>
nmap ,wG :call CtrlPWithSearchText(expand('<cword>'), 'BufTagAll')<CR>
nmap ,wf :call CtrlPWithSearchText(expand('<cword>'), 'Line')<CR>
nmap ,we :call CtrlPWithSearchText(expand('<cword>'), '')<CR>
nmap ,pe :call CtrlPWithSearchText(expand('<cfile>'), '')<CR>
nmap ,wm :call CtrlPWithSearchText(expand('<cword>'), 'MRUFiles')<CR>
nmap ,wc :call CtrlPWithSearchText(expand('<cword>'), 'CmdPalette')<CR>
" don't change working directory
let g:ctrlp_working_path_mode = 0
" ignore these files and folders on file finder
let g:ctrlp_custom_ignore = {
  \ 'dir':  '\v[\/](\.git|\.hg|\.svn|node_modules)$',
  \ 'file': '\.pyc$\|\.pyo$',
  \ }

" Syntastic ------------------------------

" show list of errors and warnings on the current file
nmap <leader>e :Errors<CR>
" check also when just opened the file
let g:syntastic_check_on_open = 1
" don't put icons on the sign column (it hides the vcs status icons of signify)
let g:syntastic_enable_signs = 0
" custom icons (enable them if you use a patched font, and enable the previous 
" setting)
"let g:syntastic_error_symbol = '✗'
"let g:syntastic_warning_symbol = '⚠'
"let g:syntastic_style_error_symbol = '✗'
"let g:syntastic_style_warning_symbol = '⚠'

" Python-mode ------------------------------

" don't use linter, we use syntastic for that
let g:pymode_lint_on_write = 0
let g:pymode_lint_signs = 0
" don't fold python code on open
let g:neocomplcache_enable_camel_case_completion = 1
let g:neocomplcache_enable_camel_case_completion = 1
let g:neocomplcache_enable_underbar_completion = 1
let g:neocomplcache_fuzzy_completion_start_length = 1
let g:neocomplcache_auto_completion_start_length = 1
let g:neocomplcache_manual_completion_start_length = 1
let g:neocomplcache_min_keyword_length = 1
let g:neocomplcache_min_syntax_length = 1
" complete with workds from any opened file
let g:neocomplcache_same_filetype_lists = {}
let g:neocomplcache_same_filetype_lists._ = '_'

" TabMan ------------------------------

" mappings to toggle display, and to focus on it
let g:tabman_toggle = 'tl'
let g:tabman_focus  = 'tf'

" Autoclose ------------------------------

" Fix to let ESC work as espected with Autoclose plugin
let g:AutoClosePumvisible = {"ENTER": "\<C-Y>", "ESC": "\<ESC>"}

" DragVisuals ------------------------------

" mappings to move blocks in 4 directions
vmap <expr> <S-M-LEFT> DVB_Drag('left')
vmap <expr> <S-M-RIGHT> DVB_Drag('right')
vmap <expr> <S-M-DOWN> DVB_Drag('down')
vmap <expr> <S-M-UP> DVB_Drag('up')
" mapping to duplicate block
vmap <expr> D DVB_Duplicate()

" Signify ------------------------------

" this first setting decides in which order try to guess your current vcs
" UPDATE it to reflect your preferences, it will speed up opening files
let g:signify_vcs_list = [ 'git', 'hg' ]
" mappings to jump to changed blocks
nmap <leader>sn <plug>(signify-next-hunk)
nmap <leader>sp <plug>(signify-prev-hunk)
" nicer colors
highlight DiffAdd           cterm=bold ctermbg=none ctermfg=119
highlight DiffDelete        cterm=bold ctermbg=none ctermfg=167
highlight DiffChange        cterm=bold ctermbg=none ctermfg=227
highlight SignifySignAdd    cterm=bold ctermbg=237  ctermfg=119
highlight SignifySignDelete cterm=bold ctermbg=237  ctermfg=167
highlight SignifySignChange cterm=bold ctermbg=237  ctermfg=227

" Window Chooser ------------------------------

" mapping
nmap  -  <Plug>(choosewin)
" show big letters
let g:choosewin_overlay_enable = 1

" Airline ------------------------------

let g:airline_powerline_fonts = 0
let g:airline_theme = 'bubblegum'
let g:airline#extensions#whitespace#enabled = 0
endif
goldie-lin commented 8 years ago

@james50428: 你那張圖裡底下的 error message 極像是在告訴你,它沒被 compiled 過。

YouCompleteMe 不是純粹的 VimScript 組成的 plugin, 他的 source tree 裡有 components 是需要手動去 compile 的。 通常需要 compile 的時機為:第一次安裝、以及經過幾次 git pull 該 git repository 之後也可能會提示你需要 re-compile。 compile 動作…主要是跑它 source tree 底下那隻 install.py 檔。 (你可以執行 ./install.py --help 來查看它有哪些參數可用。) 詳細指令與過程可參考 官方 Installation 章節

chusiang commented 8 years ago

以下記錄些建置環境和 debug 的過程:

  1. 取得 Ubuntu 16.04 的 docker image。

    $ docker run -it chusiang/vim-and-vi-mode:ubuntu16.04 bash
  2. 註解掉一些奇奇怪怪的錯誤。

    root@74f3d0eb6e02:~# vim vimrc.old
    YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+) support
    Press ENTER or type command to continue
    root@74f3d0eb6e02:~# diff .vimrc vimrc.old
    2,5c2,5
    < "set rtp+=usr/local/lib/python2.7/dist-packages/powerline/bindings/vim
    < "python from powerline.vim import setup as powerline_setup
    < "python powerline_setup()
    < "python del powerline_setup
    ---
    > set rtp+=usr/local/lib/python2.7/dist-packages/powerline/bindings/vim
    > python from powerline.vim import setup as powerline_setup
    > python powerline_setup()
    > python del powerline_setup
    58c58
    < "language message en_US.UTF-8
    ---
    > language message en_US.UTF-8
    142c142
    <     "colorscheme wombat
    ---
    >     colorscheme wombat
  3. 使用 vundle 安裝套件。

    $ vim
    :PluginInstall
  4. 跑完 vundle 時,出現 YouCompleteMe 的錯誤訊息如下。

    YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+) support
  5. 檢查 Python 版本,目前 docker container 測試環境預設使用的版本為 2.7.11。

    root@74f3d0eb6e02:/tmp# python -V
    Python 2.7.11+
  6. 查一下 dpkg,確定有預載到 Python 3.5。

    root@74f3d0eb6e02:/tmp# dpkg -l | grep -E 'python2|python3'
  7. 查了一下 Google,對於 Python 支援似乎只可透過自行編譯來解決。
  8. 移掉 vim 準備重譯。

    root@74f3d0eb6e02:~# aptitude remove vim
  9. 參照 Building Vim from source · Valloric/YouCompleteMe WikiVim 8.0 released, Install on Ubuntu 16.04 - Sysads Gazette - howto Guide, TechNew, Ubuntu, Open SourceVim Compile | Austin Pray 等文件進行編譯。

    $ sudo apt install -y ncurses-dev wget unzip gcc checkinstall \
           libncurses5-dev libgnome2-dev libgnomeui-dev \
           libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \
           libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \
           python3-dev ruby-dev lua5.1 lua5.1-dev git cmake
    $ unzip master.zip
    $ cd vim-master/src
    $ ./configure --with-features=huge \
           --enable-multibyte \
           --enable-rubyinterp \
           --enable-pythoninterp \
           --with-python-config-dir=/usr/lib/python2.7/config \
           --enable-python3interp \
           --with-python3-config-dir=/usr/lib/python3.5/config \
           --enable-perlinterp \
           --enable-luainterp \
           --enable-gui=gtk2 --enable-cscope --prefix=/usr
    $ make VIMRUNTIMEDIR=/usr/share/vim/vim80
    $ sudo make install
  10. 取得 vim 8.0。

    root@74f3d0eb6e02:~# vim --version
    VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Oct 17 2016 18:35:55)
    Included patches: 1-41
    Compiled by root@74f3d0eb6e02
  11. 安裝 YouCompleteMe。

    $ cd ~/.vim/bundle/YouCompleteMe
    $ python install.py
  12. 跑完 YCM 的 install.py 還是會出現以下錯誤。

    root@74f3d0eb6e02:~# vim
    YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+) support
chusiang commented 8 years ago

改用 NeoVim 再出發

  1. 參照 Installing Neovim · neovim/neovim Wiki 一文安裝 Neovim。
  2. 參照 How to solve "requires python 2.x support" in linux vim,and it have python 2.6.6 in my system - Stack Overflow 一文設置 YCM。
  3. 最後還是不能用?看來得等 YCM 的大大出招了。

    root@74f3d0eb6e02:~# nvim
    YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+) support
chusiang commented 8 years ago

@james50428 試試看改用其它套件,別自己編囉,晚安啦!

還有哪天搞定了記得自己關 issue。

Goldie Lin: @chusiang: 那個「requires Vim compiled with Python (2.6+ or 3.3+) support」錯誤訊息,除了自行重新編譯 vim 之外,Ubuntu 有現成的替代套件可以裝:vim-nox 或 vim-nox-py2 (若偏好 python2 而不是python3 的話)。類似的套件還有 vim-gnome、vim-gnome-py2、…、等。

racterub commented 8 years ago

打算用vagrant惹,希望是這個問題QQ

racterub commented 8 years ago

Known issue 在原YCM的repo有人提報了(怎麼之前沒找到QQ 目前還沒試過 https://github.com/Valloric/YouCompleteMe/issues/2271

chusiang commented 8 years ago

附上 @james50428 的環境建置 script。

https://github.com/staracg/Ubuntu-Env

chusiang commented 8 years ago

如果只是想要自動補齊,沒有堅持要跑 YCM 的話,看要不要換 Vim Auto Complete Popup + vim-snipmate 的 solution。:P

goldie-lin commented 8 years ago

我發現安裝 neovim 缺乏的 Python/Ruby binding libraries 就不再有那個 YouCompleteMe 錯誤訊息了。

# 也許你會需要加 sudo
gem install neovim
pip2 install neovim
pip3 install neovim

會發現是因為…在 nvim 底下執行了 :CheckHealth 指令,看到有缺乏元件的安裝提示才知道的。

health#nvim#check
================================================================================
## Remote Plugins
  - SUCCESS: Up to date

## terminfo
  - INFO: key_backspace terminfo entry: key_backspace=\177,

health#provider#check
================================================================================
## Python 2 provider
  - WARNING: No Python interpreter was found with the neovim module.  Using the first available for diagnostics.
  - WARNING: provider/pythonx: Could not load Python 2:
    /usr/bin/python2 does not have the neovim module installed. See ":help provider-python".
    /usr/bin/python2.7 does not have the neovim module installed. See ":help provider-python".
    python2.6 not found in search path or not executable.
    /usr/bin/python does not have the neovim module installed. See ":help provider-python".
  - INFO: `g:python_host_prog` is not set.  Searching for python2 in the environment.
  - INFO: Executable: /usr/bin/python2
  - INFO: Python2 version: 2.7.6
  - INFO: python2-neovim Version: unable to find nvim executable
  - ERROR: Neovim Python client is not installed.
    - SUGGESTIONS:
      - Error found was: unable to find nvim executable
      - Use the command `$ pip2 install neovim`
  - WARNING: Latest Neovim Python client version: (0.1.10)

## Python 3 provider
  - WARNING: No Python interpreter was found with the neovim module.  Using the first available for diagnostics.
  - WARNING: provider/pythonx: Could not load Python 3:
    /usr/bin/python3 does not have the neovim module installed. See ":help provider-python".
    python3.5 not found in search path or not executable.
    /usr/bin/python3.4 does not have the neovim module installed. See ":help provider-python".
    python3.3 not found in search path or not executable.
    /usr/bin/python is Python 2.7 and cannot provide Python 3.
  - INFO: `g:python3_host_prog` is not set.  Searching for python3 in the environment.
  - INFO: Executable: /usr/bin/python3
  - INFO: Python3 version: 3.4.3
  - INFO: python3-neovim Version: unable to find nvim executable
  - ERROR: Neovim Python client is not installed.
    - SUGGESTIONS:
      - Error found was: unable to find nvim executable
      - Use the command `$ pip3 install neovim`
  - WARNING: Latest Neovim Python client version: (0.1.10)

## Ruby provider
  - ERROR: Missing Neovim RubyGem
    - SUGGESTIONS:
      - Install or upgrade the neovim RubyGem using `gem install neovim`.
  - INFO: Ruby Version: ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
  - INFO: Host Executable: not found
  - INFO: Host Version: not found

看到訊息中有提示我要安裝什麼,於是裝看看。

# 也許你會需要加 sudo
gem install neovim
pip2 install neovim
pip3 install neovim

然後重開 nvim,發現 YouCompleteMe 不再報怨了。

再執行一次 :CheckHealth 指令看看。

health#nvim#check
================================================================================

## Remote Plugins
  - SUCCESS: Up to date

## Python 2 provider
  - INFO: `g:python_host_prog` is not set.  Searching for python2 in the environment.
  - INFO: Executable: /usr/bin/python2
  - INFO: Python2 version: 2.7.6
  - INFO: python2-neovim Version: 0.1.10
  - SUCCESS: Latest Neovim Python client is installed: (up to date)

## Python 3 provider
  - INFO: `g:python3_host_prog` is not set.  Searching for python3 in the environment.
  - INFO: Executable: /usr/bin/python3
  - INFO: Python3 version: 3.4.3
  - INFO: python3-neovim Version: 0.1.10
  - SUCCESS: Latest Neovim Python client is installed: (up to date)

## Ruby provider
  - SUCCESS: Found Neovim RubyGem
  - INFO: Ruby Version: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
  - INFO: Host Executable: /home/goldie/.gem/ruby/2.3.0/bin/neovim-ruby-host
  - INFO: Host Version: 0.3.1
chusiang commented 8 years ago

看來 :CheckHealth 是 NeoVim 才有的指令,又上了一課啊!

health#nvim#check
================================================================================
  - ERROR: Failed to run healthcheck for "nvim" plugin. Exception:
    Vim(let):E902: "python3" is not an executable
racterub commented 8 years ago

解決了QAQ 看來是Vundle的問題

用Vundle裝完要用以下指令

cd ~/.vim/bundle/YouCompleteme
git submodule update --init --recursive

就解決惹QQ

感謝各位QQ