{"id":2792,"date":"2012-04-07T17:42:38","date_gmt":"2012-04-07T09:42:38","guid":{"rendered":"http:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/?p=2792"},"modified":"2012-04-16T14:54:37","modified_gmt":"2012-04-16T06:54:37","slug":"compile-python-igraph-on-cenos-56","status":"publish","type":"post","link":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/?p=2792","title":{"rendered":"Compile python-igraph with custom built python on CenOS 5\/6"},"content":{"rendered":"<p>This was proved to be a very difficult task since a lot of tools were required to be re-compiled for the custom built python. I documented the sequence of tools required to be re-built below :<br \/>\nAll the newly compiled binaries\/headers\/libraries will be set to put in \/opt\/local<\/p>\n<h5>1. Compile python 2.7.2 with shared library enabled.<\/h5>\n<pre>.\/configure --prefix=\/opt\/local --enable-shared<\/pre>\n<h5>2. Setup environment variables<\/h5>\n<pre>edit ~\/.bashrc\r\nexport PATH=\/opt\/local\/bin:$PATH\r\nexport LD_LIBRARY_PATH=\/opt\/local\/lib:$LD_LIBRARY_PATH\r\nexport PYTHONPATH=\/opt\/local\/lib\/python2.7\/site-packages:$PYTHONPATH<\/pre>\n<h5>3. Compile LAPACK<\/h5>\n<pre>(make sure fortran compiler is installed)\r\nwget http:\/\/www.netlib.org\/lapack\/lapack.tgz\r\ntar xzvf lapack.tgz\r\ncp -vf make.inc.example make.inc\r\nvi make.inc\r\n# OPTS = -O2 -fPIC -m64\r\n# NOOPT = -O0 -fPIC -m64\r\n#the -m64 flags build 64-bit code (nothing for 32bit)\r\ncd ~\/src\/lapack-3.4.0\/SRC\r\nmake lib\r\ncp libtmglib.a \/opt\/local\/lib\r\ncp liblapack.a \/opt\/local\/lib<\/pre>\n<h5>4. Compile ATLAS<\/h5>\n<pre>wget http:\/\/sourceforge.net\/projects\/math-atlas\/files\/Stable\/3.8.2\/atlas3.8.2.tar.gz\r\n tar zxvf atlas3.8.2.tar.gz\r\n mkdir ATLAS_BUILD\r\n cd ATLAS_BUILD\r\n\/usr\/bin\/cpufreq-selector -g performance (turn off CPU Throttling for CentOS)\r\n\/root\/src\/ATLAS\/configure -Fa alg -fPIC --prefix=\/opt\/local \\\r\n--with-netlib-lapack=\/opt\/local\/lib\/liblapack.a\r\nmake\r\nmake check\r\nmake ptcheck\r\nmake time\r\nmake install\r\ncd lib\r\nmake shared\r\nmake ptshared\r\ncp -vf *.so  *.a \/opt\/local\/lib<\/pre>\n<h5>5. numpy<\/h5>\n<pre>wget http:\/\/voxel.dl.sourceforge.net\/sourceforge\/numpy\/numpy-1.6.1.tar.gz\r\ntar xzvf numpy-1.6.1.tar.gz\r\ncd ~\/src\/numpy-1.6.1\r\nrm -rvf build\r\ncp -vf site.cfg.example site.cfg\r\nvi site.cfg\r\n[DEFAULT]\r\nlibrary_dirs = \/opt\/local\/lib\r\ninclude_dirs = \/opt\/local\/include\r\n[blas_opt]\r\nlibraries = ptf77blas, ptcblas, atlas\r\n[lapack_opt]\r\nlibraries = lapack, ptf77blas, ptcblas, atlas\r\n\r\npython setup.py build --fcompiler=gnu95\r\npython setup.py install --prefix=\/opt\/local\r\n# verify install\r\n(cd ~\/ &amp;&amp; python -c \"import numpy; \\\r\nassert numpy.dot.__module__ == 'numpy.core._dotblas'; \\\r\nfrom numpy.linalg import lapack_lite\")<\/pre>\n<h5>6. scipy<\/h5>\n<pre>wget http:\/\/voxel.dl.sourceforge.net\/sourceforge\/scipy\/scipy-0.10.1.tar.gz\r\ntar xzvf scipy-0.10.1.tar.gz\r\nrm -rvf build\r\npython setup.py build\r\npython setup.py install --prefix=\/opt\/local\r\n# verify install\r\n(cd ~\/ &amp;&amp; python -c \"from scipy import linalg\")<\/pre>\n<h5>7. boost library (we need boost library 1.42 as required by graph tool later)<\/h5>\n<pre>get boost 1.42 from <a href=\"http:\/\/www.boost.org\/users\/history\/version_1_42_0.html\">http:\/\/www.boost.org\/users\/history\/version_1_42_0.html<\/a>\r\nedit bootstrap.sh\r\nPREFIX=\/opt\/local\r\nEPREFIX=\r\nLIBDIR=\/opt\/local\/lib\r\nINCLUDEDIR=\r\nLIBS=\"\"\r\nPYTHON=\/opt\/local\/bin\/python\r\n.\/bootstrap.sh\r\n.\/bjam\r\n.\/bjam install --prefix=\/opt\/local\r\n(move\/remove the system boost header in \/usr\/include to\r\nmake sure the later package will find and use the updated boost header and libraries)<\/pre>\n<h5>8. CGAL<\/h5>\n<pre>get CGAL from <a href=\"http:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/files\/CGAL-4.0.zip\">here<\/a>\r\ncmake . -DCMAKE_INSTALL_PREFIX=\/opt\/local  -DBUILD_SHARED_LIBS=TRUE \\\r\n-DCGAL_CXX_FLAGS=-I\/opt\/local\/include \\\r\n-DCGAL_SHARED_LINKER_FLAGS=-L\/opt\/local\/lib\r\nmake\r\nmake install<\/pre>\n<h5>9. graph-tool (require gcc 4.2 or above and boost 1.42 or above)<\/h5>\n<pre>get graph-tool from <a href=\"http:\/\/projects.skewed.de\/graph-tool\/wiki\/GraphToolDownload#StableReleaseCurrentversion:2.2.15\">here<\/a>\r\nexport CFLAGS=-I\/opt\/local\/include\r\nexport CPPFLAGS=-I\/opt\/local\/include\r\nexport CXXFLAGS=-I\/opt\/local\/include\r\nexport LDFLAGS=-L\/opt\/local\/lib\r\nexport CC=gcc44 (centos 5 only)\r\nexport CXX=g++44 (centos 5 only)\r\n.\/configure --prefix=\/opt\/local --with-boost=\/opt\/local\r\nmake (this require around 100min. for Core 2 Quad Q9400 2.66hz 4GB RAM computer)\r\nmake install<\/pre>\n<h5>10. Compile a custom swig for graphviz-python, otherwise the compile of graphviz will fail later<\/h5>\n<pre>get swig source from <a href=\"http:\/\/www.swig.org\/download.html\">http:\/\/www.swig.org\/download.html<\/a>\r\nexport CFLAGS=-I\/opt\/local\/include\r\nexport CPPFLAGS=-I\/opt\/local\/include\r\nexport CXXFLAGS=-I\/opt\/local\/include\r\nexport LDFLAGS=-L\/opt\/local\/lib\r\n.\/configure --prefix=\/opt\/local\r\nmake\r\nmake install<\/pre>\n<h5>11. Compile graphviz to get the graphviz-python (gv) module for our custom built python. It is needed by graph-tool<\/h5>\n<pre>get graphviz source from <a href=\"http:\/\/www.graphviz.org\/Download_source.php\">http:\/\/www.graphviz.org\/Download_source.php<\/a>\r\nexport CFLAGS=-I\/opt\/local\/include\r\nexport CPPFLAGS=-I\/opt\/local\/include\r\nexport CXXFLAGS=-I\/opt\/local\/include\r\nexport LDFLAGS=-L\/opt\/local\/lib\r\n.\/configure --prefix=\/opt\/local --enable-shared --enable-python=yes --enable-php=no \\\r\n--enable-tcl=no --enable-perl=no\r\nmake\r\nmake install<\/pre>\n<h5>12. python-igraph<\/h5>\n<pre>wget http:\/\/switch.dl.sourceforge.net\/sourceforge\/igraph\/igraph-0.5.4.tar.gz\r\nwget http:\/\/pypi.python.org\/packages\/source\/p\/python-igraph\/python-igraph-0.5.4.tar.gz\r\ntar xzf python-igraph-0.5.4.tar.gz\r\ntar xzf igraph-0.5.4.tar.gz\r\ncd igraph-0.5.4\r\n\u00a0export CPPFLAGS=-I\/opt\/local\/include\r\nexport CXXFLAGS=-I\/opt\/local\/include\r\nexport LDFLAGS=-L\/opt\/local\/lib\r\n.\/configure --prefix=\/opt\/local\r\nmake\r\nmake install\r\ncd python-igraph-0.5.4\r\npython setup.py install<\/pre>\n<h5>13. Compile pycairo [optional for some function of python-igraph]<\/h5>\n<pre>make sure cairo and cairo-devel packages are installed\r\nget pycairo-1.2.2.tar.gz from <a href=\"http:\/\/cairographics.org\/releases\/\">http:\/\/cairographics.org\/releases\/<\/a>\r\n(Pls note that if you get a newer version of pycairo which\r\nrequire a newer rversion of cairo library, you may need to\r\nrecompile the cairo library from source)\r\n.\/configure --prefix=\/opt\/local\r\nmake\r\nmake install<\/pre>\n<h5>14. fix graph-tool cannot find gvc library when it&#8217;s installed in a non-standard location<\/h5>\n<pre>edit \/opt\/local\/lib\/python2.7\/site-packages\/graph_tool \/draw\/__init__.py\r\n #libname = ctypes.util.find_library(\"gvc\")\r\n #if libname is None:\r\n #    raise OSError()\r\n libgv = ctypes.CDLL(\"libgvc.so\")\r\n #    libgv = ctypes.CDLL(libname)<\/pre>\n<p>Reference : <a href=\"https:\/\/projects.skewed.de\/graph-tool\/ticket\/100\">https:\/\/projects.skewed.de\/graph-tool\/ticket\/100<\/a><\/p>\n<h5>16. Compile matplotlib<\/h5>\n<pre>\r\nGet the source from <a href=\"http:\/\/matplotlib.sourceforge.net\/\">http:\/\/matplotlib.sourceforge.net\/<\/a>\r\npython setup.py build\r\npython setup.py install\r\n<\/pre>\n<h5>17. test code<\/h5>\n<pre>\r\n#!\/opt\/local\/bin\/python\r\nfrom igraph import *\r\ng = Graph.Kautz(m=3, n=2)\r\nadj = g.get_adjacency()\r\nfig = Plot(bbox=(480, 480))\r\nfig.add(g, layout=\"fr\", vertex_label=None)\r\nfig.add(adj, bbox=(360, 0, 480, 120), grid_width=0, opacity=0.7)\r\nfig.show()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This was proved to be a very difficult task since a lot of tools were required to be re-compiled for the custom built python. I documented the sequence of tools required to be re-built below : All the newly compiled binaries\/headers\/libraries will be set to put in \/opt\/local<\/p>\n<p> 1. Compile python 2.7.2 with shared library [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[3],"tags":[100],"class_list":["post-2792","post","type-post","status-publish","format-standard","hentry","category-computer","tag-python","odd"],"_links":{"self":[{"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2792"}],"version-history":[{"count":62,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2792\/revisions"}],"predecessor-version":[{"id":2794,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2792\/revisions\/2794"}],"wp:attachment":[{"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}