Installing Python’s gevent package can be a bit challanging. This blog post explains how to install it on OSX v10.8 or later without using something like ‘MacPorts’.

You will need to get XCode from Apple’s App Store and make sure to install the Command Line Tools. You do this under Preferences>Downloads (Using XCode 5 you don’t have to do that anymore, apparently).

Installing virtualenv can be done using easy_install (or pip if available):

shell $ easy_install virtualenv

Here’s how you can use virtualenv:

shell $ mkdir MyExample $ cd MyExample $ virtualenv ENV $ source ENV/bin/activate (ENV)$

The virtualenv package comes with pip, so we’ll use this instead of easy_install.

We need to install the C-library libevent. Download the latest version and do the following while in the virtual environment:

shell (ENV)$ curl -L -O (ENV)$ tar xzf libevent-2.0.21-stable.tar.gz (ENV)$ cd libevent-2.0.21-stable (ENV)$ ./configure --prefix="$VIRTUAL_ENV" (ENV)$ make && make install (ENV)$ cd $VIRTUAL_ENV/..

If all went well, install the Pyton packages greenlet and gevent. Note that the order is important.

shell (ENV)$ pip install greenlet (ENV)$ pip install gevent --global-option "-L$VIRTUAL_ENV/lib" \ --global-option "-I$VIRTUAL_ENV/include"

The order is important because gevent depends on greenlet. If you install gevent first, the extra global options will not work and you’ll get an error.

Try to import gevent and if all went well, no error should raise:

shell $ python >>> import gevent

Using OSX ‘Mavericks’ v10.9-beta you need XCode v5 Developer Preview to be able to compile libevent.