Using Boost with Python
Over the past few weeks, I’ve been doing a lot of work on my research for graduate school. One of the major developments is that I’ve migrated my prior work over to Python, which has made everything easier in the long run. Python can handle string manipulation much better than C++ or Java can, and the the language is clear, flexible, and easy to use.
I’ve also settled on the user interface to my application. It will allow both graphical and textual input modes, which will be interpreted as a directed graph of functional units. This should work really well once I get it all implemented, but I’ve been having a few issues with parsing and processing the input files.
The goal was to find a library or module that would allow me to read in a file and perform a breadth-first search over the nodes of the graph. After some exploring, I decided that Boost had a graph library that would do just what I wanted. The problem is that Boost is written for C++. A wrapper called bgl-python would let me use the library within my code, but the last time it had been updated was in 2005. Unsurprisingly, the wrapper no longer worked with Boost.
After some serious hacking, I’ve finally resolved the issue. Now I’m able to call Boost’s graph algorithms from Python, at the cost of having to run old versions of Boost and Bjam. If you really want to use the Boost graph library python bindings, here’s what you have to do:
#boost
#Download boost_1_33_1_beta.tar.gz from http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041&release_id=369578 to current directory.
wget http://www.eecs.wsu.edu/~krobinso/research/boost_1_33_1_beta.tar.gz
tar -xvf boost_1_33_1_beta.tar.gz
mv -f boost_1_33_1 /usr/local#bjam
#Download boost-jam-3.1.11-1-linuxx86.tgz from http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=72941&release_id=344791 to the current directory.
wget http://www.eecs.wsu.edu/~krobinso/research/boost-jam-3.1.11-1-linuxx86.tgz
tar -xvf boost-jam-3.1.11-1-linuxx86.tgz
mv -f boost-jam-3.1.11-1-linuxx86/bjam /usr/bin/#bgl-python
wget http://www.osl.iu.edu/~dgregor/bgl-python/files/bgl-python-0.9.tar.gz
tar -xvf bgl-python-0.9.tar.gz
mv -f bgl-python-0.9 /usr/local/boost_1_33_1/
#edit this line for the python version
(cd /usr/local/boost_1_33_1/bgl-python-0.9; bjam -sPYTHON_VERSION=2.5)#setup
#edit this line for the python version (default 2.5), python location (default /usr/lib/python{pythonversion}, and ld path (default /usr/lib)
(cd /usr/local/boost_1_33_1/bgl-python-0.9; mv -f boost/ /usr/lib/python2.5/; mv -f libboost_python.so* /usr/lib/;)#cleanup
rm boost_1_33_1_beta.tar.gz
rm boost-jam-3.1.11-1-linuxx86.tgz
rm bgl-python-0.9.tar.gz
rm -rf boost-jam-3.1.11-1-linuxx86
Of course, I’m not even going to try to guarantee this process. If you use these instructions, you do so at your own risk. In the future, I might try to throw this all into a shell script that is actually reliable. Better yet, I might take some time and rewrite the bgl-python wrapper so it works with the current version of Boost.


Wow. It's Quiet Here...
Be the first to start the conversation!