IPython tab completes only some modules
Asked Answered
E

3

6

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.

Exclusive answered 12/10, 2009 at 6:5 Comment(4)
Do you mean that import Be<tab> doesn't work? or BeautifulSoup.<tab> doesn't work?Lindsaylindsey
The former. After typing out the name by hand and importing, tab completion kicks in for the members of the modules.Exclusive
Same problem here, with Python 2.6.2 and IPython 0.10 on Mac OS X…Mizzenmast
The IndexError would indicate that state is not in matches. Can you try printing them both in the exception handler?Lindsaylindsey
O
13

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.

Osmic answered 2/9, 2010 at 21:4 Comment(0)
L
2

right at the end of Ipython/completer.py is this code:


        except:
            #from IPython.ultraTB import AutoFormattedTB; # dbg
            #tb=AutoFormattedTB('Verbose');tb() #dbg
# If completion fails, don't annoy the user. return None

Perhaps uncommenting it will give you a clue

Lindsaylindsey answered 12/10, 2009 at 6:20 Comment(1)
No luck. Nothing was "Verbose" about the lack of completion.Exclusive
M
0

Locally installed, non-egg modules can have their name tab-completed, when doing import, but egg modules cannot (IPython 0.10, Python 2.6.2, Mac OS X).

I would suggest to file a feature request / bug report with IPython!

Mizzenmast answered 12/10, 2009 at 7:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.