Quantcast
Channel: Geert JM Vanderkelen » Geert Vanderkelen
Viewing all articles
Browse latest Browse all 25

Installing gevent inside a virtual environment on OSX

$
0
0

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
(ENV)shell>

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 https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
(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.


Viewing all articles
Browse latest Browse all 25

Trending Articles