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: libghmm.so.1: cannot open shared object file: No such file or directory

I tried to find out whether libghmm.so.1 was installed by using
$ sudo updatedb
$ locate libghmm.so.1

then got
~/ghmm/ghmm/.libs/libghmm.so.1
~/ghmm/ghmm/.libs/libghmm.so.1.0.0
/usr/local/lib/libghmm.so.1
/usr/local/lib/libghmm.so.1.0.0

The messages indicated that the libghmm.so.1 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: libghmm.so.1 ...

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 libghmm.so.1 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 libghmm.so.1 file into the path of /usr/lib/ for the other two PCs and everything is okay now.

8 comments:

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

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

    ReplyDelete
  3. Thank you very much for the trick!

    ReplyDelete
  4. Anonymous4:31 PM

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

    ReplyDelete
  5. That was very helpful.

    ReplyDelete
  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 ghmmwrapper.py
    Of course, replace /usr/local/lib' by the dir where libghmm.so.1 is.
    Works for me...!

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

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

    ReplyDelete
  8. Awesome, this just worked.

    ReplyDelete