Sunday, September 20, 2009

[SW] GHMM in Python: importing problem

In July, I installed a library of HMM called GHMM. When I had no experience about Python and therefore ignored the part of Python bindings. With the amazing capabilities of Python+SciPy, I began to notice the possibility to learm more about HMM using the Python bindings of GHMM. Therefore I followed the installation steps on GHMM webpage and got it worked on one of my PC.

Today, I tried to follow the same procedures to install GHMM in my another Ubuntu and Debian system on another two PCs, but got some problems.

After installing the GHMM as well as the Python bindings, I imported ghmm in iPython but got errors:

ImportError: cannot open shared object file: No such file or directory

I tried to find out whether was installed by using
$ sudo updatedb
$ locate

then got

The messages indicated that the had been in my system, but the Python somehow couldn't find it. So there must be some setting needed to make it work.

There have been some discussions in the mailing lists of GHMM as follows.
[Ghmm-list] cant find _ghmmwrapper
[Ghmm-list] ImportError: ...

With the above information, I add the LD_LIBRARY_PATH into .bashrc as
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

It works. :-)

Some information found during my solution-searching:
The 3rd and 4th links are beyond my knowledge, so I decide not to bother with them now... :-p

memo (090923): I found the file has been in the path of ``/usr/lib/'' instead of ``/usr/local/lib/'' in the first Ubuntu PC which has ghmm installed without any problem. Therefore I tried to cp the file into the path of /usr/lib/ for the other two PCs and everything is okay now.


  1. You are genius. I've been trying to get this sorted all day! Thanks!

  2. You are welcome. It's good to know that my post helps.

  3. Thank you very much for the trick!

  4. Anonymous4:31 PM

    Thanks for the note! It helped me a lot :)

  5. That was very helpful.

  6. If you want to avoid having to set the LD_LIBRARY_PATH, which is bad, you can add the following line at the top of
    Of course, replace /usr/local/lib' by the dir where is.
    Works for me...!

    # TBM HACK
    import imp
    fp = None
    fp, pathname, description = imp.find_module('libghmm', ['/usr/local/lib'])
    except ImportError:
    print ' TBM HACK FAILED'
    if fp is not None:
    imp.load_module('libghmm', fp, pathname, description)
    except ImportError:

  7. Thanks, Thierry BM. I didn't know the imp module. Your approach is more like ``Python way.''

  8. Anonymous6:54 PM

    Awesome, this just worked.