IPython tab completes only some modules

巧了我就是萌 提交于 2019-12-06 01:33:49

问题


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.


回答1:


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.




回答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




回答3:


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!



来源:https://stackoverflow.com/questions/1552961/ipython-tab-completes-only-some-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!