Installing gevent from pypi on OSX

Attempting to install opencenter on OSX was failing as it requires gevent, which is a python module with native C that needs compiling. The last error is:

error: Setup script exited with error: command 'llvm-gcc-4.2' failed with exit status 1

This error threw me off, it made me think there was a problem with apple’s llvm-gcc-4.2 compiler, so I went and installed gcc, but that didn’t help.

Stack overflow pointed out that the real error is a missing header file:

Processing dependencies for python-opencenter==1.0.0
Searching for gevent
Reading http://pypi.python.org/simple/gevent/
Reading http://www.gevent.org/
Reading http://gevent.org/
Best match: gevent 0.13.8
Downloading http://pypi.python.org/packages/source/g/gevent/gevent-0.13.8.tar.gz#md5=ca9dcaa7880762d8ebbc266b11252960
Processing gevent-0.13.8.tar.gz
Running gevent-0.13.8/setup.py -q bdist_egg --dist-dir /var/folders/pv/k2l3p6w15xg4ydds642_z5jhvf8_cf/T/easy_install-NT_xI7/gevent-0.13.8/egg-dist-tmp-kskfWC
In file included from gevent/core.c:253:
gevent/libevent.h:9:19: error: event.h: No such file or directory

This is fixed by installing libevent via macports:

sudo port install libevent

However that doesn’t seem to put the header files in a default search path, so extra dirs must be specified in CFLAGS:

CFLAGS="-I /opt/local/include -L /opt/local/lib" python setup.py install