Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython tab completes only some modules

I'm using the EPD version of python and IPython. After installing some modules using easy_install I notice that, although they can be imported, they cannot be tab completed. They exist on the path but, while included modules (pylab, readline, math) can be completed, these new modules cannot.

Anyone know what I should look into to find the problem? I've checked that the packages are in the same place as other modules:

In [1]: import pylab

In [2]: pylab
Out[2]: <module 'pylab' from '/Library/Frameworks/Python.framework/Versions/5.0.0/lib/python2.5/site-packages/pylab.pyc'>

In [3]: import BeautifulSoup

In [4]: BeautifulSoup
Out[4]: <module 'BeautifulSoup' from '/Library/Frameworks/Python.framework/Versions/5.0.0/lib/python2.5/site-packages/BeautifulSoup-3.1.0.1-py2.5.egg/BeautifulSoup.pyc'>

Maybe something not handling the .eggs correctly? Thanks.

Update: Following up on gnibbler's post, I've found that the tab completion hits an exception at line 633 in completer.py at:

    try:
        ret = self.matches[state].replace(magic_prefix,magic_escape)
        return ret
    except IndexError:
        return None

But what is causing the failiure...

Update:

In [5]: from Bea<tab_here>
*** COMPLETE: <Bea> (0)
matches: []
state: 0

So this is just saying that the matches list is an empty set: there are no matches. It is still not finding the module. I'll try to investigate where matches is getting the modules its looking for when I have time.

like image 717
physicsmichael Avatar asked Oct 12 '09 06:10

physicsmichael


1 Answers

I found an answer to this question yesterday, after I got tired of this behavior.

It seems that IPython has a simple database with all the modules it can find in sys.path. Every time you install a new module you have to write the magic

In [1]: %rehashx

so that IPython regenerates its database. Then you can have TAB-completion of new modules.

like image 122
Carlos Cordoba Avatar answered Oct 12 '22 23:10

Carlos Cordoba