Compiling MacVim with Python 2.7

I love the brilliant Vim plugin pyflakes-vim, which highlights errors & warnings, and since I got a MacBook for work, I’ve been using MacVim a lot.

This combination has a problem, that MacVim uses the OSX system default Python 2.6, so pyflakes is unable to handle Python 2.7 syntax, such as set literals. These are marked as a syntax errors, which prevents the rest of the file from being parsed.

The solution is to compile your own MacVim, using Python 2.7 instead of the system Python. The following commands got MacVim compiled for me:

#!/bin/bash
git clone git://github.com/b4winckler/macvim.git
cd macvim/src
export LDFLAGS=-L/usr/lib
./configure \
    --with-features=huge \
    --enable-rubyinterp \
    --enable-perlinterp \
    --enable-cscope \
    --enable-pythoninterp \
    --with-python-config-dir=/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
make
open MacVim/build/Release
echo Drag MacVim.app to your Applications directory

Without the LDFLAGS setting, I was missing some symbols at link. The –with-python-config-dir entry came from typing ‘which python’ to find where my Python 2.7 install lives, and modifying that result to find its ‘config’ directory (whatever that is) near to the binary.

As indicated, install by dragging the resulting macvim/src/MacVim/build/Release/MacVim.app into your Applications directory.

Open up MacVim, and check out the built-in Python version:

:python import sys; print sys.version
2.7.1 (r271:86882M, Nov 30 2010, 10:35:34)

And files with set literals are now correctly parsed for errors.

Update: This only works if the Python 2.7 is your default ‘python’ executable. Otherwise, or if you get “ImportError: No module named site”, see Richard’s comments below.

6 thoughts on “Compiling MacVim with Python 2.7

  1. Ah, the problem is that I’m trying to get it to use the non-default Python (my default is still the system install of Python 2.6). The MacVIM configuration gets mighty confused.

    Had to delve into the configure script to figure this out, but I needed to prefix the configure line setting vi_cv_path_python:

    “vi_cv_path_python=/usr/local/bin/python2.7 ./configure –enable-pythoninterp …”

    (–with-python-config-dir wasn’t needed – configure determined the correct location without my help)

  2. Sadly the build doesn’t work for me. Attempting to open any Python source results in “ImportError: No module named site” printed to the console. I’m using a built-from-source Python 2.7.2…

  3. @horneds, that looks really cool, I hadn’t seen it before. Thanks for the pointer, I’ll try it out over the weekend.

Leave a Reply