domingo, 29 de enero de 2012

Installing gevent

If you're a Python noob like me, installing gevent is not trivial. In my case, I'm using Ubuntu 10.04. These are the steps to follow:

1. Install libevent package (apt or synaptic)
2. sudo easy_install greenlet
3. sudo easy_install gevent
4. ldconfig
5. test that 'import gevent' and 'from gevent import socket' work.

Step 4 was necessary in my case since step 5 wasn't working, but you may try to see if it does in your case.

Now, I was interested specifically in the datagram server. At the moment of writing this, the release version of gevent was 0.13.6, which didn't include it, so I had to perform a check out of the latest version in the repository.

However, I didn't want to install it as I wanted to be able to switch between different versions or easily move a setup to another computer. Therefore, I wanted to manually build it into a given directory. For this, I had to do a few more undocumented steps:

1. sudo easy_install cython
2. (in gevent root folder) python setup.py build, which generates a build in build/lib.linux...
3. In my Eclipse project, link the build folder as an external library source.

Now, I wanted to be able to execute my project without eclipse... so I added a main file which set up the paths:

...

GEVENT_PATH = "../gevent/build/lib.linux-i686-2.6"

import os
import sys

# append paths to PYTHONPATH
sys.path.append(os.path.abspath(GEVENT_PATH))

# begin importing and using gevent!


...

And finally... that was it!

No hay comentarios:

Publicar un comentario