How can I use the Homebrew Python with Homebrew MacVim on Mountain Lion?
I originally asked and answered this question: How can I use the Homebrew Python version with Homebrew MacVim?
These instructions worked on Snow Leopard using Xcode 4.0.1 and associated developer tools. However, they no longer seem to work on Mountain Lion with Xcode 4.4.1.
My goal is to leave the system's version of Python completely untouched, and to only install PyPI packages into Homebrew's site-packages
directory. I want to use the vim_bridge package in MacVim, so I need to compile MacVim against the Homebrew version of Python.
I've edited the MacVim formula to add these to the arguments:
--enable-pythoninterp=dynamic
--with-python-config-dir=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/Current/lib/python2.7/config
Then I install with the command:
brew install macvim --override-system-vim --custom-icons --with-cscope --with-lua
However, it still seems to be somehow using Python 2.7.2 from the system. This seems strange to me because it also seems to be using the correct executable.
:python print(sys.version)
2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
:python print(sys.executable)
/usr/local/bin/python
$ /usr/local/bin/python --version
Python 2.7.3
$ /usr/local/bin/python -c "import sys; print(sys.version)"
2.7.3 (default, Aug 12 2012, 21:17:22)
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))]
$ readlink /usr/local/lib/python2.7/config
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/Current/lib/python2.7/config
I've removed everything in /usr/local
and reinstalled Homebrew by running these commands:
$ ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
$ brew install git mercurial python ruby
$ brew install macvim
(nope, still broken)
$ brew remove macvim
$ ln -s /usr/local/Cellar/python/..../python2.7/config /usr/local/lib/python2.7/config
$ brew install macvim
Not a good answer here, but I wanted to leave a note confirming that I encountered this exact same issue on a ~fresh Mountain Lion install.
There is some interesting discussion at the link below which suggests a controversial bug between the MacVim and Python configure files ... but making the suggested change in the config file did not work for me (assuming I did it right).
https://stackoverflow.com/questions/6490513/vim-failing-to-compile-with-python-on-os-x/8276426#8276426
What did work for me is, ahem, biting the bullet and just symlinking the system python install over to the homebrew. Feels dirty, but at least I get full omnicomplete working on third party modules now...
cd /System/Library/Frameworks/Python.framework/Versions
sudo mv Current Current-sys
sudo ln -s /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7 Current
brew install macvim
sudo mv Current Current-brew
sudo mv Current-sys Current
I just pushed a fix1 so that MacVim builds with a brewed Python (if you have one) and successfully load the powerline (I installed it after my brewed python via pip install pip install git+git://github.com/Lokaltog/powerline
). Don't forget to set your ~/.vimrc
.
Don't ever rename things inside of /System
.
Please, revert local changes, restore your /System
, brew update
and brew rm macvim
and finally brew install macvim
.