Geert JM Vanderkelen

Installing gevent inside a virtual environment on OSX

Installing gevent inside a virtual environment on OSX

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
shell> cd MyExample
shell> virtualenv ENV
shell> source ENV/bin/activate

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:

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

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

(ENV)shell> pip install greenlet
(ENV)shell> 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
python> import gevent

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

2 thoughts on “Installing gevent inside a virtual environment on OSX

  1. Damjan

    gevent 1.0 is in a almost-released state and is highly preferred over the 0.3.x version that you get with pip. And it also requires libev which it has bundled, so no need for libevent.

    I just do:

    pip install –user git+

    and it installs it in ~/.local/lib/…/…

Leave a Reply

Your email address will not be published. Required fields are marked *

− 6 = 1

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>