首页 > 代码库 > Mac Yosemite上安装macvim和YouCompleteMe

Mac Yosemite上安装macvim和YouCompleteMe

今天在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, requiredfiletype off                  " required " set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()" alternatively, pass a path where Vundle should install plugins"call vundle#begin(‘~/some/path/here‘) " let Vundle manage Vundle, requiredPlugin gmarik/Vundle.vim Plugin altercation/vim-colors-solarizedPlugin Lokaltog/powerline, {rtp: powerline/bindings/vim/}Plugin kien/ctrlp.vimPlugin scrooloose/syntasticPlugin Valloric/YouCompleteMe " All of your Plugins must be added before the following linecall vundle#end()            " requiredfiletype plugin indent on    " required

在vim中运行命令

:BundleInstall

完成后进入目录中

cd ~/.vim/bundle/YouCompleteMe./install.sh --clang-completer

编译完成后,运行vim结果出错.

$ vimVim: Caught deadly signal ABRTVim: 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.7sudo mv /Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versionssudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/2.7sudo rm /System/Library/Frameworks/Python.framework/Versions/Currentsudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/Currentsudo rm /usr/bin/pydocsudo rm /usr/bin/pythonsudo rm /usr/bin/pythonwsudo rm /usr/bin/python-configsudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc /usr/bin/pydocsudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python /usr/bin/pythonsudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw /usr/bin/pythonwsudo 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.pysavePATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"export PATH

改变Python版本后,执行vim就不再出现段错误了.

 

参考文献:

1. github issue#8

2. installing-homebrew-macvim-with-youcompleteme-on-yosemite 

3. Installing / Updating Python on OS X

 

Mac Yosemite上安装macvim和YouCompleteMe