I was exploring a project concerned with reverse engineering some file formats (https://gitorious.org/re-lab/tools) and I needed to run a python script. This python script requires libgsf (the gnome structured file library: http://projects.gnome.org/libgsf/ ), however the debian/ubuntu packages for this aren't built with python support!
This led to errors such as:
frankster@linux-virtualbox:~/relab/tools/oletoy$ ./view.py
Traceback (most recent call last):
File "./view.py", line 23, in <module>
import Doc, cmd
File "/home/frankster/relab/tools/oletoy/Doc.py", line 19, in <module>
import ole,mf,svm,cdr,clp,rx2
File "/home/frankster/relab/tools/oletoy/ole.py", line 23, in <module>
import vsd, xls, ppt, vba, doc
File "/home/frankster/relab/tools/oletoy/vsd.py", line 19, in <module>
import gtk,gsf
ImportError: No module named gsf
Getting libgsf compiled was a bit of a pain so here are some tips that may be helpful. I initially attempted to modify the ubuntu package and simply enable the configuration switch for python support. However there are some problems with the paths for python includes in the debian build scripts that I didn't get to the bottom of. So instead of building a custom ubuntu package, I uninstalled the official libraries and built my own version. I was still able to use the debian package build infrastructure to automatically fetch the source code and the build-dependencies which made things a little easier!
sudo apt-get source libgsf
sudo apt-get install python-dev
sudo apt-get build-dep libgsf
cd libgsf-1.14.21
./configure --with-python
make
sudo make install
Check that you had all required python development libraries installed during the configure stage by looking for the following lines towards the end:
checking for python... /usr/bin/python
checking for python version... 2.7
checking for python platform... linux2
checking for python script directory... ${prefix}/lib/python2.7/dist-packages
checking for python extension module directory... ${exec_prefix}/lib/python2.7/dist-packages
checking for headers required to compile python extensions... found
checking for PYGTK... yes
checking for pygtk-codegen-2.0... /usr/bin/pygtk-codegen-2.0
yes
If you only saw some of these lines, then the python component won't get built!
Once you have got this far, your python script should now detect the gsf module. As your manual install of libgsf will have gone into the /usr/local/ tree, your python script may not be able to locate the library it needs to link to. If this happens you will see an error like the following:
Traceback (most recent call last):
File "./view.py", line 23, in <module>
import Doc, cmd
File "/home/frankster/relab/tools/oletoy/Doc.py", line 19, in <module>
import ole,mf,svm,cdr,clp,rx2
File "/home/frankster/relab/tools/oletoy/ole.py", line 23, in <module>
import vsd, xls, ppt, vba, doc
File "/home/frankster/relab/tools/oletoy/vsd.py", line 19, in <module>
import gtk,gsf
File "/usr/local/lib/python2.7/dist-packages/gsf/__init__.py", line 8, in <module>
from _gsf import *
ImportError: libgsf-1.so.114: cannot open shared object file: No such file or directory
If this happens you can solve it by telling the linker where it needs to look to find the library:
$ LD_LIBRARY_PATH=/usr/local/lib ./view.py
You can of course make this permanent in your .profile or .bashrc or whatever.