如何升级kernmagic以修复此ipython错误?

时间:2013-01-29 02:13:52

标签: ipython

我最近使用

升级了我的Enthought Python发行版
sudo easy_install -U ipython

但是,当我使用ipython命令启动ipython时,出现错误:

David-Faux-MacBook-Air:core davidfaux$ ipython
Python 2.7.2 |EPD 7.2-2 (32-bit)| (default, Sep  7 2011, 09:16:50) 
Type "copyright", "credits" or "license" for more information.

IPython 0.13.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
[TerminalIPythonApp] Error in loading extension: kernmagic
Check your config files in /Users/davidfaux/.ipython/profile_default
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/ipython-0.13.1-py2.7.egg/IPython/core/extensions.pyc in load_extension(self, module_str)
     90                 __import__(module_str)
     91         mod = sys.modules[module_str]
---> 92         return self._call_load_ipython_extension(mod)
     93 
     94     def unload_extension(self, module_str):

/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/ipython-0.13.1-py2.7.egg/IPython/core/extensions.pyc in _call_load_ipython_extension(self, mod)
    122     def _call_load_ipython_extension(self, mod):
    123         if hasattr(mod, 'load_ipython_extension'):
--> 124             return mod.load_ipython_extension(self.shell)
    125 
    126     def _call_unload_ipython_extension(self, mod):

/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/kernmagic/__init__.py in load_ipython_extension(ip)
     28 
     29 def load_ipython_extension(ip):
---> 30     activate(ip)
     31     activate_aliases(ip)

/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/kernmagic/__init__.py in activate(ip, *args)
     14             continue
     15         magic_name = name[len('magic_'):]
---> 16         ip.shell.define_magic(magic_name, getattr(mymagics, name))
     17 
     18 def activate_aliases(ip, *args):

AttributeError: 'TerminalInteractiveShell' object has no attribute 'shell'

我google了一下,我发现很多帖子都说在ipython配置文件中注释掉这一行。

c.TerminalIPythonApp.extensions = ['kernmagic']

我发现注释掉一个ipython文件是个粗略的...后来,我发现kernmagic fixed the issue和ipython。

如何在ipython发行版中升级kernmagic,以免此错误消失?

6 个答案:

答案 0 :(得分:5)

这对我有用:

hg clone https://bitbucket.org/robertkern/kernmagic
cd kernmagic
python setup.py build
python -c "import setuptools;execfile('setup.py')" bdist_egg
egginst dist/kernmagic-0.0.0-py2.7.egg

答案 1 :(得分:3)

您可以评论/删除配置文件中的行,如果您不使用kernmagic则没有问题。实际上.ipython / profile_xxx文件夹是为人们改变的。

否则如果你真的想升级kern魔法,我建议你卸载,删除文件并从当前源重新安装。

另外IIRC kern魔术问题不是仅使用EPD的原始IPython,所以你不应该害怕从配置文件和系统中删除它。

答案 2 :(得分:3)

对于那些没有运行EPD分发python的人(或Rich的解决方案不起作用):

首先,我在Mac OS X 10.8.4上运行Python 2.7.5 | Anaconda 1.6.0(x86_64)|。

正如马特所说,最简单的方法就是注释出这样的一行:

# A list of dotted module names of IPython extensions to load.
c.TerminalIPythonApp.extensions = ['kernmagic']

我发现了这个:

~/.ipython/profile_default/ipython_config.py

应该位于1/3左右。值得指出的是,这是一个临时解决方案 - 我不知道kernmagic做了什么,或者它是否是一个重要的ipython扩展。

答案 3 :(得分:1)

我也遇到过这个问题,我在Windows环境中,我在

中找到了这一行
UIWindow * window

var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

//Slect initial viewController
self.window = UIWindow(frame: UIScreen.mainScreen.bounds)
UIViewController * viewController
var preferences: NSUserDefaults = NSUserDefaults.standardUserDefaults()
var userId: String = preferences["userId"]

if userId != nil {
    viewController = storyboard.instantiateViewControllerWithIdentifier("NavigationController")
}
else {
    viewController = storyboard.instantiateViewControllerWithIdentifier("LoginViewController")
}
self.window.rootViewController = viewController
self.window.makeKeyAndVisible()

如上所述,最简单的方法就是注释出如下所示的行:

C:\Users\Li\.ipython\profile_default\ipython_config.py

答案 4 :(得分:0)

Enthought更新了kernmagic,所以Enthought的enpkg在EPD 7.3和ipython 0.13.1上为我解决了同样的问题:

sudo enpkg kernmagic

答案 5 :(得分:0)

我刚刚为python3创建了一个快速而又脏的kernmagic端口。在python-2.x下出现此问题时,它也可能有效。

Here is a link to the code。您只需将整个kernlab文件夹放入site-packages目录即可。它似乎是一个纯粹的python库,所以它应该在任何平台上工作。

祝你好运!