今天在macvim上安裝YouCompleteMe的時候,碰到一個運行vim崩潰的錯誤.查了半天終於解決!
先上一下安裝macvim的過程
# install xcode and command line tools $ xcode-select --install # install homebrew $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # install python $ brew install python # install macvim $ brew install macvim
然后編輯.vimrc
set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " alternatively, pass a path where Vundle should install plugins "call vundle#begin('~/some/path/here') " let Vundle manage Vundle, required Plugin 'gmarik/Vundle.vim' Plugin 'altercation/vim-colors-solarized' Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'} Plugin 'kien/ctrlp.vim' Plugin 'scrooloose/syntastic' Plugin 'Valloric/YouCompleteMe' " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required
在vim中運行命令
:BundleInstall
完成后進入目錄中
cd ~/.vim/bundle/YouCompleteMe ./install.sh --clang-completer
編譯完成后,運行vim結果出錯.
$ vim Vim: Caught deadly signal ABRT Vim: Finished. Abort trap: 6
查了一圈發現,加一個參數后能正常工作
$ DYLD_FORCE_FLAT_NAMESPACE=1 vim
但畢竟這不是一個辦法,最后在github上的issue頁面上看到問題的解決辦法:
brew unlink python
運行后依然無效!!!!崩潰!!!
然后繼續看下去
$ otool -L /usr/local/Cellar/macvim/7.4-73_1/MacVim.app/Contents/MacOS/Vim | grep -i python /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.6)
而我的系統上默認的python是2.7.9,而且路徑為/Library/Frameworks/Python.framework/Versions/2.7/python!
OK找到問題所在了,現在的任務就是需要把這兩個Python的版本調整成為一致!!!!
HOW to do it? Google之找到辦法,把所有的操作整理到一起給大家:
sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7 sudo mv /Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/2.7 sudo rm /System/Library/Frameworks/Python.framework/Versions/Current sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/Current sudo rm /usr/bin/pydoc sudo rm /usr/bin/python sudo rm /usr/bin/pythonw sudo rm /usr/bin/python-config sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc /usr/bin/pydoc sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python /usr/bin/python sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw /usr/bin/pythonw sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config /usr/bin/python-config
需要詳細解釋的童鞋,可以查看這篇文檔.
執行這段shell之后,需要編輯~/.bash_profile將系統默認的Python路徑指向/System/Library這個文件夾
# Setting PATH for Python 2.7 # The orginal version is saved in .bash_profile.pysave PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}" export PATH
改變Python版本后,執行vim就不再出現段錯誤了.
參考文獻:
2. installing-homebrew-macvim-with-youcompleteme-on-yosemite
3. Installing / Updating Python on OS X