Issue #150 resolved

python api: recoll.connect() only available when starting in python site-packages/recoll directory

Anonymous created an issue

depending on where I start python on my system I have recoll.connect() available or not. My first guess was that this was some path problem, so I tried to append the path before loading the module, but that doesn't change anything.

best regards

robin

####### HOME DIRECTORY with path added to sys

limo@rs:~> python Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2 Type "help", "copyright", "credits" or "license" for more information.

>>> import sys 
>>> sys.path.append('/usr/local/lib64/python2.7/site-packages/recoll')
>>> import recoll
>>> recoll.__
recoll.__class__(         recoll.__format__(        recoll.__new__(           recoll.__repr__(
recoll.__delattr__(       recoll.__getattribute__(  recoll.__package__        recoll.__setattr__(
####### PYTHON DIRECTORY

limo@rs:/usr/local/lib64/python2.7/site-packages/recoll> python Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2 Type "help", "copyright", "credits" or "license" for more information.

>>> import sys
>>> sys.path
['', '/usr/lib/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/PIL', '/usr/local/lib64/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode']
>>> import recoll
>>> recoll.
recoll.Db(                recoll.__doc__            recoll.__new__(           recoll.__str__(
recoll.Doc(               recoll.__file__           recoll.__package__        recoll.__subclasshook__(
recoll.Query(             recoll.__format__(        recoll.__reduce__(        recoll.connect(
recoll.SearchData(        recoll.__getattribute__(  recoll.__reduce_ex__(     recoll.doctypeptr
recoll.__class__(         recoll.__hash__(          recoll.__repr__(          
recoll.__delattr__(       recoll.__init__(          recoll.__setattr__(       
recoll.__dict__           recoll.__name__           recoll.__sizeof__( 
recoll.__dict__           recoll.__hash__(          recoll.__path__           recoll.__sizeof__(
recoll.__doc__            recoll.__init__(          recoll.__reduce__(        recoll.__str__(
recoll.__file__           recoll.__name__           recoll.__reduce_ex__(     recoll.__subclasshook__(
>>> sys.path
['', '/usr/lib/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/PIL', '/usr/local/lib64/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode', '/usr/local/lib64/python2.7/site-packages/recoll']

Comments (12)

  1. medoc repo owner

    Hi,

    I am not too sure what may be happening here, but notice that in the first version, you are appending the recoll directory to the path, which means that if there is a stale recoll file earlier, it will be used.

    What I'd try would be to make sure to clean up any recoll python code, then reinstall and retry. I'd use something like the following to make sure I have everything:

     find /usr/local/lib*/python* /usr/lib*/python* | grep -i recoll
    
  2. biomimetics

    I must have made a mistake posting the first issue: the problem remains also if I do not try to append a path: here is what I have done:

    navigate to /usr/local/lib64/python2.7/site-packages/ open a python shell: recoll connect is not available change to the recoll subdirectory open a python shell: recoll connect is there I thought that if I am not in the recoll subdirectory I may manually append the full path beforehand, but irc that didn't do the trick.

    best regards and many thanks for recoll!!

    robin recoll is version 1.19.5

    be

    limo@rs:/usr/local/lib64/python2.7/site-packages> python
    Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import recoll
    >>> recoll.__
    recoll.__class__(         recoll.__file__           recoll.__init__(          recoll.__path__           recoll.__setattr__(
    recoll.__delattr__(       recoll.__format__(        recoll.__name__           recoll.__reduce__(        recoll.__sizeof__(
    recoll.__dict__           recoll.__getattribute__(  recoll.__new__(           recoll.__reduce_ex__(     recoll.__str__(
    recoll.__doc__            recoll.__hash__(          recoll.__package__        recoll.__repr__(          recoll.__subclasshook__(
    >>> recoll.__
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute '__'
    >>> quit()
    limo@rs:/usr/local/lib64/python2.7/site-packages> cd recoll/
    limo@rs:/usr/local/lib64/python2.7/site-packages/recoll> python
    Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import recoll
    >>> recoll.
    recoll.Db(                recoll.__delattr__(       recoll.__getattribute__(  recoll.__package__        recoll.__sizeof__(
    recoll.Doc(               recoll.__dict__           recoll.__hash__(          recoll.__reduce__(        recoll.__str__(
    recoll.Query(             recoll.__doc__            recoll.__init__(          recoll.__reduce_ex__(     recoll.__subclasshook__(
    recoll.SearchData(        recoll.__file__           recoll.__name__           recoll.__repr__(          recoll.connect(
    recoll.__class__(         recoll.__format__(        recoll.__new__(           recoll.__setattr__(       recoll.doctypeptr
    >>> recoll.
    KeyboardInterrupt
    >>> quit
    Use quit() or Ctrl-D (i.e. EOF) to exit
    >>> 
    >>>  find /usr/local/lib*/python* /usr/lib*/python* | grep -i recoll
      File "<stdin>", line 1
        find /usr/local/lib*/python* /usr/lib*/python* | grep -i recoll
        ^
    IndentationError: unexpected indent
    >>> quit()
    limo@rs:/usr/local/lib64/python2.7/site-packages/recoll>  find /usr/local/lib*/python* /usr/lib*/python* | grep -i recoll
    /usr/local/lib64/python2.7/site-packages/recoll
    /usr/local/lib64/python2.7/site-packages/recoll/__init__.pyc
    /usr/local/lib64/python2.7/site-packages/recoll/recoll.so
    /usr/local/lib64/python2.7/site-packages/recoll/rclconfig.py
    /usr/local/lib64/python2.7/site-packages/recoll/rclconfig.pyc
    /usr/local/lib64/python2.7/site-packages/recoll/rclextract.so
    /usr/local/lib64/python2.7/site-packages/recoll/__init__.py
    /usr/local/lib64/python2.7/site-packages/Recoll-1.0-py2.7.egg-info
    
  3. medoc repo owner

    Ok, I think I got it.

    The structure of the recoll modules changed with release 1.19. You should use:

    from recoll import recoll
    

    to gain access to the recoll module (there are now 2 separate modules under the recoll package, using recoll as both the package name and the module name may not have been a good idea).

    When in the top directory, using 'import recoll' imports the package itself. When in the subdir, it imports the recoll.so module that is in there.

    Conclusion: move out from /usr/local/xxx and use 'from recoll import recoll'. Also check the Python section in the recoll user manual: http://www.lesbonscomptes.com/recoll/usermanual/usermanual.html#RCL.PROGRAM.API.PYTHON

  4. biomimetics

    just works! thanks a lot!

    on the manual page for python usage you write: The SearchData class

    A SearchData object allows building a query by combining clauses, for execution by 
    Query.executesd(). It can be used in replacement of the query language approach. The interface is going to change a little, so no detailed doc for now...
    

    do you already have an estimate on when you will finalise the interface and have a detailed documentation? I looked at your example """Example for using the ''searchdata''' structured query interface. """ which looks very much like what I would like to use more.

  5. biomimetics

    Now I remember that I had tried the

    from recoll import recoll

    but that doesn't work if you are in the recoll subdirectory yourself! but works once you navigate somewhere else.

    limo@rs:~/AdditionalSoftware/recoll-1.19.5/python/recoll/build/lib.linux-x86_64-2.7/recoll> python
    Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from recoll import recoll
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: cannot import name recoll
    >>> 
    limo@rs:~/AdditionalSoftware/recoll-1.19.5/python/recoll/build/lib.linux-x86_64-2.7/recoll> cd ..
    limo@rs:~/AdditionalSoftware/recoll-1.19.5/python/recoll/build/lib.linux-x86_64-2.7> python
    Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from recoll import recoll
    >>> 
    
  6. biomimetics

    Problem again.

    my earlier post was not fully true. there are some paths where the

    from recoll import recoll

    works and other where it fails...

    limo@rs:~/Dokumente/Riskmanagement/SoftwareEntwicklung/05_Recoll> python
    Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from recoll import recoll
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "recoll.py", line 6, in <module>
        from recoll import recoll
    ImportError: cannot import name recoll
    >>> 
    limo@rs:~/Dokumente/Riskmanagement/SoftwareEntwicklung/05_Recoll> cd ~/AdditionalSoftware/recoll-1.19.5/python/recoll/build/lib.linux-x86_64-2.7
    limo@rs:~/AdditionalSoftware/recoll-1.19.5/python/recoll/build/lib.linux-x86_64-2.7> python
    Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from recoll import recoll
    >>> 
    
  7. medoc repo owner

    Not too sure what's happening here, but I wonder if the case where it fails are those when there is a recoll.so in the common directory. Please clean-up the python/recoll install if necessary, then reinstall it and only use it from a normal location (not from the build directory and not from the installed lib one).

    About the searchdata interface, it's little used, but I just tried the sample which is included in the source, and it seems to work. I'm not too sure what I intended to change in the interface, at this point I have no plans. I am attaching a sligthly edited version of the sample, try it, and if this does not do what you want, we can work on it.

    About

  8. biomimetics

    the solution is indeed:

    you may not start python in a directory where you have a file called recoll.ANYEXTIONS

    so if you have recoll.py or recoll.pyc or recoll.so in that directory python will throw an importerror.

    please set the ticket status to fixed

  9. Log in to comment