jeffdaily / parasail-python

Python bindings for the parasail C library.
Other
87 stars 17 forks source link

ArgumentError when doing example #4

Closed daveuu closed 8 years ago

daveuu commented 8 years ago

Python 3.5.1 (default, Mar 3 2016, 09:29:07) Type "copyright", "credits" or "license" for more information.

IPython 4.1.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import parasail

In [2]: parasail.sw_scan_16("asdf", "asdf", -11, -1, parasail.blosum62)
---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
<ipython-input-2-0b8d7596534e> in <module>()
----> 1 parasail.sw_scan_16("asdf", "asdf", -11, -1, parasail.blosum62)

/home/play/git_repos/parasail-python/parasail/__init__.py in sw_scan_16(s1, s2, open, extend, matrix)
   1954 def sw_scan_16(s1, s2, open, extend, matrix):
   1955     return Result(_lib.parasail_sw_scan_16(
-> 1956         s1, len(s1), s2, len(s2), open, extend, matrix),
   1957         len(s1), len(s2))
   1958 

ArgumentError: argument 1: <class 'TypeError'>: wrong type

Thanks. I should say I had to edit parasail/__init__.py and hard wire the path to libparasail.so because setting LD_LIBRARY_PATH=$PREFIX/lib (with PREFIX correct) ended with an import error:

In [1]: import parasail
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-1-91ca26eb93af> in <module>()
----> 1 import parasail

/home/play/git_repos/parasail-python/parasail/__init__.py in <module>()
     27     _lib = ctypes.CDLL(_libpath)
     28 else:
---> 29     _lib = ctypes.CDLL(_libname)
     30
     31 def _make_nd_array(c_pointer, shape, dtype=numpy.intc, order='C', own_data=True):

/usr/lib/python3.5/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    345
    346         if handle is None:
--> 347             self._handle = _dlopen(self._name, mode)
    348         else:
    349             self._handle = handle

OSError: libparasail.so: cannot open shared object file: No such file or directory
jeffdaily commented 8 years ago

This is great! Pardon my excitement that you're the first person (that I know of) to try the python bindings of parasail!

Looks like parasail works with Python 2 but not 3. I will fix this. I don't have a lot of experience with Python 3 but I want to get this working for both of them.

I don't know the best practices for using ctypes with C libraries. I recall reading about the pitfalls of trying to locate libraries but this appears to be the problem for you? I think my README is not up to date. I will also look into making it easier to find and load the parasail library.

Stay tuned... and thanks for providing an issue report instead of simply shrugging your shoulders and moving on.

jeffdaily commented 8 years ago

Hi David,

It looks like this was caused by Python3 using unicode and my incorrect assumption that byte strings would be used with my code as it is done in Python2.

I found advice on http://python3porting.com/problems.html says to use a b() function that wraps the strings passed to the parasail functions, converting to bytes if Py3 and leaving them alone if Py2. I just pushed the commit 6ef26b4cd3781c992fef45e0672a3ada4527b2f2. I installed python3 on my mac laptop and tried it out and I was able to use it.

As for the PREFIX issue. Still working on the best way to locate the parasail library during start-up.

jeffdaily commented 8 years ago

I have updated the README.rst (renamed from README.md) with installation details. Also, the example incorrectly used negative values for the gap open and extension penalties. PREFIX is no longer used so please see the README.rst for details.

daveuu commented 8 years ago

Hi Jeff

Install via pip works perfectly for me now in Python2 and Python3 (sorry for slow response crazy couple of weeks . . .)

thanks.