{"id":40,"date":"2011-08-26T02:06:26","date_gmt":"2011-08-26T02:06:26","guid":{"rendered":"http:\/\/francisfisher.me.uk\/problem\/?p=40"},"modified":"2012-07-19T18:54:56","modified_gmt":"2012-07-19T18:54:56","slug":"running-a-python-script-that-requires-libgsf-on-ubuntu-11-04","status":"publish","type":"post","link":"https:\/\/francisfisher.me.uk\/problem\/2011\/running-a-python-script-that-requires-libgsf-on-ubuntu-11-04\/","title":{"rendered":"Running a python script that requires libgsf on Ubuntu 11.04"},"content":{"rendered":"<p>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 <a href=\"http:\/\/packages.debian.org\/changelogs\/pool\/main\/libg\/libgsf\/libgsf_1.14.8-1lenny2\/changelog#versionversion1.14.2-1\">aren't built with python support<\/a>!<\/p>\n<p>This led to errors such as:<\/p>\n<pre>frankster@linux-virtualbox:~\/relab\/tools\/oletoy$ .\/view.py\r\nTraceback (most recent call last):\r\n\u00a0 File \".\/view.py\", line 23, in &lt;module&gt;\r\n\u00a0\u00a0\u00a0 import Doc, cmd\r\n\u00a0 File \"\/home\/frankster\/relab\/tools\/oletoy\/Doc.py\", line 19, in &lt;module&gt;\r\n\u00a0\u00a0\u00a0 import ole,mf,svm,cdr,clp,rx2\r\n\u00a0 File \"\/home\/frankster\/relab\/tools\/oletoy\/ole.py\", line 23, in &lt;module&gt;\r\n\u00a0\u00a0\u00a0 import vsd, xls, ppt, vba, doc\r\n\u00a0 File \"\/home\/frankster\/relab\/tools\/oletoy\/vsd.py\", line 19, in &lt;module&gt;\r\n\u00a0\u00a0\u00a0 import gtk,gsf\r\nImportError: No module named gsf<\/pre>\n<p>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!<\/p>\n<pre>sudo apt-get source libgsf\r\nsudo apt-get install python-dev\r\nsudo apt-get build-dep libgsf\r\ncd libgsf-1.14.21\r\n.\/configure --with-python\r\nmake\r\nsudo make install<\/pre>\n<p>Check that you had all required python development libraries installed during the configure stage by looking for the following lines towards the end:<\/p>\n<pre>checking for python... \/usr\/bin\/python\r\nchecking for python version... 2.7\r\nchecking for python platform... linux2\r\nchecking for python script directory... ${prefix}\/lib\/python2.7\/dist-packages\r\nchecking for python extension module directory... ${exec_prefix}\/lib\/python2.7\/dist-packages\r\nchecking for headers required to compile python extensions... found\r\nchecking for PYGTK... yes\r\nchecking for pygtk-codegen-2.0... \/usr\/bin\/pygtk-codegen-2.0\r\nyes<\/pre>\n<p>If you only saw some of these lines, then the python component won't get built!<\/p>\n<p>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:<\/p>\n<pre>Traceback (most recent call last):\r\n\u00a0 File \".\/view.py\", line 23, in &lt;module&gt;\r\n\u00a0\u00a0\u00a0 import Doc, cmd\r\n\u00a0 File \"\/home\/frankster\/relab\/tools\/oletoy\/Doc.py\", line 19, in &lt;module&gt;\r\n\u00a0\u00a0\u00a0 import ole,mf,svm,cdr,clp,rx2\r\n\u00a0 File \"\/home\/frankster\/relab\/tools\/oletoy\/ole.py\", line 23, in &lt;module&gt;\r\n\u00a0\u00a0\u00a0 import vsd, xls, ppt, vba, doc\r\n\u00a0 File \"\/home\/frankster\/relab\/tools\/oletoy\/vsd.py\", line 19, in &lt;module&gt;\r\n\u00a0\u00a0\u00a0 import gtk,gsf\r\n\u00a0 File \"\/usr\/local\/lib\/python2.7\/dist-packages\/gsf\/__init__.py\", line 8, in &lt;module&gt;\r\n\u00a0\u00a0\u00a0 from _gsf import *\r\nImportError: libgsf-1.so.114: cannot open shared object file: No such file or directory<\/pre>\n<p>If this happens you can solve it by telling the linker where it needs to look to find the library:<\/p>\n<pre>$ LD_LIBRARY_PATH=\/usr\/local\/lib .\/view.py<\/pre>\n<p>You can of course make this permanent in your .profile or .bashrc or whatever.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/posts\/40"}],"collection":[{"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":4,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":47,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/posts\/40\/revisions\/47"}],"wp:attachment":[{"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/francisfisher.me.uk\/problem\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}