March 01, 2011

Installing Pygments 1.4 on MacOS X

I'm using Jekyll to power my blog. It's a very simple framework which lends itself perfectly to developers used to coding files and the Git workflow, and comes without any of the bloat required for a client-facing CMS.

Jekyll comes with built-in support for Pygments; a syntax highlighter supporting hundreds of languages. This article details the officially supported method for installing Pygments 1.4 on Mac OS X Snow Leopard. You will need to have Python installed already—this is provided by the Mac OS X Developer Tools—and you'll need to be logged into an administrator account.

First, establish the version of Python you have:

$ python --version
Python 2.6.1

Download the Setuptools package which corresponds to your version of Python. In this case, it will be setuptools-0.6c11-py2.6.egg.

Run the Setuptools package as root:

$ sudo sh setuptools-0.6c11-py2.6.egg
...
Finished processing dependencies for setuptools==0.6c11

This will add a new command you can run: easy_install. With this we can install Pygments (again as root):

$ sudo easy_install Pygments
...
Finished processing dependencies for Pygments

Now, in our config.yml file for our Jekyll blog, we can add:

pygments: true

This will add support for syntax highlighting using the {% highlight %} liquid tags. Enjoy!