How can I use the Homebrew Python with Homebrew MacVim on Mountain Lion?

5,336

Solution 1

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

Solution 2

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.

Share:
5,336

Related videos on Youtube

Stephen Jennings
Author by

Stephen Jennings

Updated on September 18, 2022

Comments

  • Stephen Jennings
    Stephen Jennings over 1 year

    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
    
    • Rash
      Rash over 11 years
      Have you tried running brew link python and then python --version on a fresh terminal?
    • Stephen Jennings
      Stephen Jennings over 11 years
      @user1099816 Python is already linked in /usr/local/bin, and the Python version in my path is 2.7.3.
    • Randall Hunt
      Randall Hunt over 11 years
      I can't reproduce this... I think we're missing something about you're environment. The symlink to: /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/V‌​ersions/Current/lib/‌​python2.7/config -- mentioned in the previous question... is that backwards?
    • Stephen Jennings
      Stephen Jennings over 11 years
      @ranman /usr/local/lib/python2.7/config is symlinked to /usr/local/Cellar/.../lib/python2.7/config, which contains config.c, among other files.
    • HikeMike
      HikeMike over 11 years
      Are you installing the same formula version and the exact same MacVim version on both systems? Maybe something broke between releases and your upgrades are unrelated?
    • Stephen Jennings
      Stephen Jennings over 11 years
      @DanielBeck The MacVim formula did change a little, but mostly syntactically (I must have used commit 69b3681 based on the date of my first question, which uses the same tarball). The only real difference between the formulae is removing a few environment variables for the CC compiler, and requiring Ruby 1.8.
  • Stephen Jennings
    Stephen Jennings over 11 years
    A-ha! So I tried first modifying the Makefile, then also symlinking the framework in /System/Library/Frameworks, and now it works even after restoring the symlink. I'll go back and figure out if both were necessary, and maybe try to dig into what the heck is happening, but you definitely get my thanks (and bounty; not bad getting 200 rep for your first answer)!
  • Stephen Jennings
    Stephen Jennings over 11 years
    Yes, even if I put the Makefile back, as long as I have /System/Library/.../Current symlinked to Homebrew's version, MacVim compiles with 2.7.3.
  • Hola
    Hola over 11 years
    Awesome! So glad it worked out. Happy Vimming.
  • Jeremy Cantrell
    Jeremy Cantrell over 11 years
    Just wanted to say that this fixed my problem as well.
  • SamTebbs33
    SamTebbs33 over 9 years
    I had this problem for a couple of days too and once I'd used brew install macvim, I used the command brew link --overwrite macvim and then it worked perfectly!