Python, igraph in CentOS
Build Python 2.7 with package igraph 0.5.4 in CentOS 5.5 , all from source and install to non-standard path :
Source placed in : /usr/local/python-igraph/src/
Destination Build path : /usr/local/python-igraph/
The sequence of installation is : python -> lapack -> Atlas -> Numpy -> scipy -> boost -> CGAL -> graph-tool -> igraph -> python-igraph -> swig -> graphviz -> cairo -> pycairo
0. Ensure you have cmake, gfortran44,gcc44,g++44 in your system , or else install with command :
yum install gcc44 gcc44-c++ gcc44-gfortran libgfortran44 libstdc++44-devel
yum install cmake
1. Download and install Python2.7.3rc2 (Python ver 3 does not work with igraph packages) in a shell script
#!/bin/sh
cd /usr/local/python-igraph/src/Python-2.7.3rc2
make clean
make distclean
./configure –prefix=/usr/local/python-igraph –enable-shared
make
make install
2. Download and compile lapack 3.2.1 (Fortran routines for solving Linear Algebra) :
cd /usr/local/python-igraph/src/lapack-3.2.1/SRC
cp make.inc.example make.inc
Edit /usr/local/python-igraph/src/lapack-3.2.1/SRC/make.inc (-fPIC : positive independent code , used for creating share lib):
OPTS = -O2 -fPIC -m64
NOOPT = -O0 -fPIC -m64
Then start compile in a shell script :
#!/bin/sh
cd /usr/local/python-igraph/src/lapack-3.2.1/SRC
make -j 4
That will create an static library “lapack_LINUX.a” which will be needed in building of Atlas .
3. Download and Compile Atlas3.8.3 (“Automatically Tuned Linear Algebra Software” which produces a BLAS (Basic Linear Algebra Subprograms) library) in a shell script:
#!/bin/sh
mkdir MyObj
cd /usr/local/python-igraph/src/ATLAS/MyObj
../configure -b 64 -Fa alg -fPIC –with-netlib-lapack=/usr/local/python-igraph/src/lapack-3.2.1/lapack_LINUX.a -Si cputhrchk 0
make build
make check
make ptcheck
make time
cd lib
make shared
make ptshared
Then copy the static *.a and shared libraries *.so to /usr/local/python-igraph/lib
4. Download and Install Numpy ( fundamental package for scientific computing with Python)
cd /uac/spc/misc/webdemo/sepc716/src/numpy-1.6.1
rm -r build
cp -vf site.cfg.example site.cfg
Edit site.cfg with the following :
[DEFAULT]
library_dirs = /usr/local/python-igraph/lib
include_dirs = /usr/lcoal/python-igraph/include
#
[blas_opt]
libraries = ptf77blas, ptcblas, atlas
#
[lapack_opt]
libraries = lapack, ptf77blas, ptcblas, atlas
Then start the installation in shell script :
#!/bin/sh
export PYTHON_VERSION=2.7
export PATH=/usr/local/python-igraph/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/python-igraph/bin
cd /usr/local/python-igraph/src/numpy-1.6.1
python2.7 setup.py build –fcompiler=gnu95
python2.7 setup.py install –prefix=/usr/local/python-igraph/
Verify by :
python2.7 -c “import numpy”
5. Download and start installation of scipy 0.10.1 (Open Source Library of Scientific Tools) in shell script :
#!/bin/sh
export PYTHON_VERSION=2.7
export PATH=/usr/local/python-igraph/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/python-igraph/lib
cd /usr/local/python-igraph/src/scipy-0.10.1
python2.7 setup.py build –fcompiler=gnu95
python2.7 setup.py install –prefix=/usr/local/python-igraph/
6. Download boost 1.42.0 (provides free peer-reviewed portable C++ source libraries.) Newer versions of boost libraries does not work for graph tool , so stay with the lowest and claim to work version .
Edit variables in bootstrap.sh :
PREFIX=/usr/local/python-igraph
LIBDIR=/usr/local/python-igraph/lib
PYTHON=/usr/local/python-igraph/bin/python2.7
and start installation boost 1.42.0 in a shell script :
export PYTHON_VERSION=2.7
export LDFLAGS=-L/usr/local/python-igraph/lib
export PATH=/usr/local/python-igraph/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/python-igraph/lib
cd /usr/local/python-igraph/src/boost_1_42_0
./bootstrap.sh –prefix=/usr/local/python-igraph/
./bjam install
In order to avoid misuse of system boost include and libraries for future compilation of graph tool (which does not consistently read CPPFLAGS or CXXFLAGS variables ) , do the following temporarily :
mv /usr/include/boost /usr/include/boost.old
mkdir /usr/lib/libboost-old; mv /usr/lib/libboost* /usr/lib/boost-old
mkdir /usr/lib64/libboost-old; mv /usr/lib64/libboost* /usr/lib64/boost-old
You can revert the above after the whole installation is finished.
7. Download CGAL4.0 and start installation in a shell script :
#!/bin/sh
export CC=gcc44
export LDFLAGS=-L/usr/local/python-igraph/lib
export CPPFLAGS=-I/usr/local/python-igraph/include/
export CXXFLAGS=-I/usr/local/python-igraph/include/
export CFLAGS=-I/usr/local/python-igraph/include/
export CXX=g++44
export PYTHON_VERSION=2.7
export PATH=/usr/local/python-igraph/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/python-igraph/lib
cd /usr/local/python-igraph/src/CGAL-4.0
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/python-igraph -DBUILD_SHARED_LIBS=TRUE -DCMAKE_C_COMPILER=gcc44 -DCMAKE_CXX_COMPILER=g++44 -DCGAL_CXX_FLAGS=-I/usr/local/python-igraph/include/
make
make install
8. Download and Install graph-tool-2.2.15 (Ensure to use gcc ver 4.2 or above) :
#!/bin/sh
export CC=gcc44
export LDFLAGS=-L/usr/local/python-igraph/lib
export CPPFLAGS=-I/usr/local/python-igraph/include/
export CXXFLAGS=-I/usr/local/python-igraph/include/
export CFLAGS=-I/usr/local/python-igraph/include/
export CXX=g++44
export PYTHON_VERSION=2.7
export PATH=/usr/local/python-igraph/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/python-igraph/lib
cd /usr/local/python-igraph/src/graph-tool-2.2.15
make clean
make distclean
./configure CPPFLAGS=”-I/usr/local/python-igraph/include” LDFLAGS=”-L/usr/local/python-igraph/lib” –prefix=/usr/local/python-igraph/ –with-boost=/usr/local/python-igraph
make
make install
9. Download igraph 0.5.4 and python-igraph-0.5.4 and then Install in a shell script :
#!/bin/sh
export PYTHON_VERSION=2.7
export PATH=/usr/local/python-igraph/bin:$PATH
cd /usr/local/python-igraph/src/igraph-0.5.4
export CPPFLAGS=-I/usr/local/python-igraph/include
export CXXFLAGS=-I/usr/local/python-igraph/include
export LDFLAGS=-L/usr/local/python-igraph/lib
./configure –prefix=/usr/local/python-igraph
make
make install
cd /usr/local/python-igraph/src/python-igraph-0.5.4
python2.7 setup.py install
10. To test using the python package as normal user with csh or tcsh as shell :
setenv PATH /usr/local/python-igraph/bin:$PATH
setenv LD_LIBRARY_PATH /usr/local/python-igraph/lib:$LD_LIBRARY_PATHpython2.7
>>> import igraph
>>> import igraph.test
>>> igraph.test.test()
11. The graph plotting samples will need some more packages like graphviz and cairo in order to output an image . Before these installation, build swig 2.0.4 from source . First ensure you have ensure you have pcre-devel and pcre in the system first, or else install them with
yum -y pcre pcre-devel
Then build and install swig 2.0.4 from script :
export CC=gcc44
export LDFLAGS=-L/usr/local/python-igraph/lib
export CPPFLAGS=-I/usr/local/python-igraph/include/
export CXXFLAGS=-I/usr/local/python-igraph/include/
export CFLAGS=-I/usr/local/python-igraph/include/
export CXX=g++44
export PYTHON_VERSION=2.7
export PATH=/usr/local/python-igraph/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/python-igraph/lib
cd swig-2.0.4
./configure –prefix=/usr/local/python-igraph
make
make install
12. Before building graphviz , ensure you don’t have gts-devel in the system, if so , remove it first . Build graphviz-2.28.0 from source :
export CC=gcc44
export LDFLAGS=-L/usr/lib64 -L/usr/local/python-igraph/lib
export CPPFLAGS=-I/usr/local/python-igraph/include/ -I/usr/include
export CXXFLAGS=-I/usr/local/python-igraph/include/ -I/usr/include
export CFLAGS=-I/usr/local/python-igraph/include/ -I/usr/include
export CXX=g++44
export PYTHON_VERSION=2.7
export PATH=/usr/local/python-igraph/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/python-igraph/lib:/usr/lib64
cd graphviz-2.28.0
make clean
make distclean
./configure –prefix=/usr/local/python-igraph –enable-python27=yes –enable-java=no –enable-lua=no –enable-ocaml=no –enable-perl=no –enable-php=no
make
make install
13. Build cairo 1.2.2 from source :
#!/bin/sh
export CC=gcc44
export LDFLAGS=-L/usr/lib64 -L/usr/local/python-igraph/lib
export CPPFLAGS=-I/usr/local/python-igraph/include/ -I/usr/include
export CXXFLAGS=-I/usr/local/python-igraph/include/ -I/usr/include
export CFLAGS=-I/usr/local/python-igraph/include/ -I/usr/include
export CXX=g++44
export PYTHON_VERSION=2.7
export PATH=/usr/local/python-igraph/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/python-igraph/lib:/usr/lib64
cd cairo-1.2.2
./configure –prefix=/usr/local/python-igraph/
make
make install
14. Build python package pycairo-1.2.2 from source :
#!/bin/sh
export CC=gcc44
export LDFLAGS=-L/usr/lib64 -L/usr/local/python-igraph/lib
export CPPFLAGS=-I/usr/local/python-igraph/include/ -I/usr/include
export CXXFLAGS=-I/usr/local/python-igraph/include/ -I/usr/include
export CFLAGS=-I/usr/local/python-igraph/include/ -I/usr/include
export CXX=g++44
export PYTHON_VERSION=2.7
export PATH=/usr/local/python-igraph/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/python-igraph/lib:/usr/lib64
cd pycairo-1.2.2
./configure –prefix=/usr/local/python-igraph/
make
make install
15. To test the sample for using igraph :
#!/usr/local/python-igraph/bin/python2.7
from igraph import *
g = Graph.Kautz(m=3, n=2)
adj = g.get_adjacency()
fig = Plot(bbox=(380, 380))
fig.add(g, layout=”fr”, vertex_label=None)
fig.add(adj, bbox=(260, 0, 280, 20), grid_width=0, opacity=0.7)
fig.show()
Output :
Special Note : If you got the error like below while running the python script :
File “/usr/local/python-igraph/lib/python2.7/site-packages/graph_tool/draw/__init__.py”, line 565, in graph_draw
libgv.agclose(gvg)
NameError: global name ‘libgv’ is not defined.
Probably because you are not using the right libgv.so . You have to edit the file : /usr/local/python-igraph/lib/python2.7/site-packages/graph_tool/draw/__init__.py like below to specifically load the just built libgvc.so.6.0.0 :
try:
#libname = ctypes.util.find_library(“gvc”)
#if libname is None:
# raise OSError()
libgv = ctypes.CDLL(“libgvc.so.6.0.0”)