5

I recently upgraded my Enthought Python distribution with

sudo easy_install -U ipython

However, when I start up ipython with the ipython command, I get an error:

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'

I googled around, and many posts I found said to comment out this line in an ipython configuration file.

c.TerminalIPythonApp.extensions = ['kernmagic']

I find it sketchy to comment out an ipython file though... later, I found that kernmagic fixed the issue with ipython.

How do I upgrade kernmagic in my ipython distribution so that this error goes away?

dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206

6 Answers6

5

This worked for me:

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
Rich Signell
  • 14,842
  • 4
  • 49
  • 77
  • 1
    Hah. I always thought that was short for kernel magic (ip kernel), but no, its just some dude's name. – meawoppl Feb 13 '14 at 23:31
4

You can comment/remove the line in your configuration file, there is no issues with that if you do not use kernmagic. Actually the .ipython/profile_xxx folder are made for people to change things.

Otherwise if you really want to upgrade kern magic, I suggest you uninstall, remove the files and reinstall it from the current source.

Also IIRC the kern magic issue does not come with raw IPython only with EPD, so you shouldn't be afraid of removing it from config files and system.

Matt
  • 27,170
  • 6
  • 80
  • 74
4

For those who are not running EPD's distribution of python (or if Rich's solution didn't work):

First of all, I'm running Python 2.7.5 |Anaconda 1.6.0 (x86_64)|, on Mac OS X 10.8.4.

As Matt has stated, it is easiest to simply comment out the line that looks like this:

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

I found this in:

~/.ipython/profile_default/ipython_config.py

It should be located around 1/3 of the way down. It's worth pointing out that this is a temporary solution - I have no idea what kernmagic does or if it's an important ipython extension.

astromax
  • 6,001
  • 10
  • 36
  • 47
0

Enthought has updated kernmagic, so Enthought's enpkg fixed the same problem for me on EPD 7.3 and ipython 0.13.1:

sudo enpkg kernmagic
E. Douglas
  • 234
  • 1
  • 3
  • 11
0

I've just created a quick-and-dirty port of kernmagic to python3. It may also work when this problem arises under python-2.x.

Here is a link to the code. All you need to do is drop the entire kernlab folder into your site-packages directory. It seems to be a pure python library, so it ought to work on any platform.

Good luck!

Wesley
  • 1,324
  • 1
  • 11
  • 27
0

I also faced this problem, I'm on windows environment, I found that line in

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

As stated, it is easiest to simply comment out the line that looks like this:

# A list of dotted module names of IPython extensions to load.
c.TerminalIPythonApp.extensions = ['kernmagic']
Pythoner
  • 5,265
  • 5
  • 33
  • 49