Testing Environment for Python igraph

Sometimes, the need may arise to install igraph and python-igraph locally (i.e. under a user's home directory as an "isolated" environment that won't affect the global system's installation). For instance, you may have the current stable version installed on your computer, but you want to test the newest, unreleased version. This guide will show you how to create a local, isolated environment to test igraph and python-igraph. This is accomplished using the virtualenv tool.

We will assume an Ubuntu Linux OS. We also assume that you already have the following Ubuntu packages installed the system: libcairo-dev, python-setuptools.

Install virtualenv

Change to your home directory and install the virtualenv python package. We will assume your home directory is in /home/username.

$ cd /home/username
$ sudo easy_install virtualenv
Use virtualenv to create an isolated python testing environment

Let us assume you will name your testing environment igraphtest.

$ virtualenv --no-site-packages igraphtest
Install (locally) igraph C library

Download the version of igraph you wish to test. We will assume igraph has been downloaded as a tarball and is named igraph-0.XX.tar.gz. We will install it into our newly created test environment. Notice adminstrative privelages are not required for the "make install" because you are installing to your own home directory.

$ tar -xzvf igraph-0.XX.tar.gz
$ cd igraph-0.XX
$ ./configure --prefix=/home/username/igraphtest
$ make
$ make install
Download and install pycairo

We will assume the pycairo package is named pycairo-0.XX.tar.gz. IMPORTANT: installing pycairo using setup.py or easy_install will not work (in my experience), even when using the virtualenv. You must install this way:

$ tar -xzvf pycairo-0.XX.targz
$ cd pycairo-0.XX
$ ./configure --prefix=/home/username/igraphtest
$ make
$ make install
Switch to the virtualenv environment to use the locally installed version of python.
$ cd ~/
$ source ./igraphtest/bin/activate
Download and install python-igraph

We will assume the python-igraph package has been downloaded as python-igraph-0.XX.

$ tar -xzvf python-graph-0.XX.tar.gz
$ cd python-igraph-0.XX

Now, modify the setup.py file as follows:
LIBIGRAPH_FALLBACK_INCLUDE_DIRS = ['/home/username/igraphtest/include']
LIBIGRAPH_FALLBACK_LIBRARIES = ['igraph', '/home/username/igraphtest/lib']

Now, while in your virtualenv, execute the following:

$ python setup.py install
Using your virualenv.

If you're not already in virtualenv, do this:

$ cd ~/
$ source ./igraphtest/bin/activate

Modify your LD_LIBRARY_PATH:

$ export LD_LIBRARY_PATH=/home/username/igraphtest/lib

Now test your isolated, locally installed python-igraph environment (which is independent of the python and igraph installed globally on your OS in /usr/lib, /usr/local/lib, and such).

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph
Exiting your virtualenv test environment
$ deactivate

You can handle the setting and unsetting of LD_LIBRARY_PATH automatically by incorporating it into the ~/igraphtest/bin/activate script.

Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.