IPython选项卡仅完成部分模块
我正在使用 EPD 版本的 python 和 IPython。使用 easy_install 安装一些模块后,我注意到,虽然可以导入它们,但无法使用 Tab 键完成它们。它们存在于路径中,但是虽然包含的模块(pylab、readline、math)可以完成,但这些新模块却不能。
有人知道我应该检查什么才能找到问题吗?我已经检查过这些包是否与其他模块位于同一位置:
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'>
也许有些东西没有正确处理 .eggs
?谢谢。
更新:在 gnibbler 的帖子之后,我发现 tab 补全在completer.py 的第 633 行遇到了异常:
try:
ret = self.matches[state].replace(magic_prefix,magic_escape)
return ret
except IndexError:
return None
但是是什么导致了失败...
更新:
In [5]: from Bea<tab_here>
*** COMPLETE: <Bea> (0)
matches: []
state: 0
所以这只是说匹配列表是一个空集:没有匹配。仍然没有找到该模块。当我有时间的时候,我会尝试调查 matches
在哪里获取它正在寻找的模块。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我厌倦了这种行为后,昨天我找到了这个问题的答案。
看起来 IPython 有一个简单的数据库,其中包含它可以在 sys.path 中找到的所有模块。每次安装新模块时,您都必须编写魔法,
以便 IPython 重新生成其数据库。然后你就可以用 TAB 补全新模块了。
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 magicso that IPython regenerates its database. Then you can have TAB-completion of new modules.
Ipython/completer.py 的末尾是以下代码:
也许取消注释会给你一个线索
right at the end of Ipython/completer.py is this code:
Perhaps uncommenting it will give you a clue
本地安装的非egg模块在
导入
时可以通过制表符完成名称,但egg模块则不能(IPython 0.10、Python 2.6) .2、Mac OS X)。我建议使用 IPython 提交功能请求/错误报告!
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!