Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Note: For Mountain Lion, see: How can I use the Homebrew Python with Homebrew MacVim on Mountain Lion?

I've installed Python 2.7 with Homebrew on Mac OS X Snow Leopard. When I install MacVim using brew install macvim, it compiles with Python support, but is compiled against the system's Python installation. This can be seen by running the command:

:python print(sys.version)

2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)]

However, Vim seems to be using the Python executable that's in my path:

:python print(sys.executable)

/usr/local/bin/python

This causes problems for Vim scripts using vim_bridge, such as vim-rst-tables (can't import module "re").

How can I compile Vim against my Homebrewed Python version?

share|improve this question
    
Seems to be fixed now: github.com/Homebrew/homebrew/issues/26496 – Will Feb 12 '14 at 22:38
up vote 14 down vote accepted

First, remove MacVim if you've already installed it: brew remove macvim

Next, edit MacVim's Formula with the command: brew edit macvim. Find the arguments list (begins with args = %W[ ...), and modify this line:

--enable-pythoninterp

Change it to these two lines:

--enable-pythoninterp=dynamic
--with-python-config-dir=/usr/local/lib/python2.7/config

(this config dir should be symlinked to /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/Current/lib/python2.7/config)

Now when you reinstall MacVim with brew install macvim, it will use your Python 2.7 installation.

:python print(sys.version)

2.7.3 (default, Apr 16 2012, 23:20:02) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)]
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .