Self-importance. Entitlement. Snobbery.

Link brew MacVim against brew Python

Aug 26 2014

I’m constantly tinkering with my environment; I’m on an endless quest to simplify and automate it as much as possible. Between my shell, my editors and my window management solution, I’ve got things running pretty smoothly now…for the most part. Recently, my brew-installed MacVim had been giving me fits—seg faults right and left. Here’s how I solved the problem.

As it turned out, the problem was that brew MacVim only links against the system Python, and I had a brew-installed version of Python. When trying to launch MacVim, Bad Things Happened. I spent far longer than I care to remember Googling for a solution, and found a few differing recommendations. By cobbling them together—and a fair amount of trial and error—I was finally able to get it to work. Here’s how you can do it too:

  1. Create a soft link to the python config directory:

    1
    2
    
    cd /usr/local/lib/python2.7
    ln -s /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/Current/lib/python2.7/config config
    
  2. Edit the brew Macvim formula: brew edit macvim, then add the following configure flags under elsif build.with? "python":

    1
    2
    
    --enable-pythoninterp
    --with-python-config-dir=/usr/local/lib/python2.7/config
    
  3. Add a soft link to the python include directory to make Python/Python.h accessible:

    1
    2
    
    cd /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/Current/include/python2.7
    ln -s `pwd` Python
    
  4. Finally, make sure linking and building flags are the same when installing:

    1
    
    DYLD_FORCE_FLAT_NAMESPACE=1 vi_cv_path_python_plibs="-L/usr/local/lib/python2.7/config -lpython2.7 -ldl -u _PyMac_Error" brew install --verbose macvim -- python