[IPython-dev] Two basic Notebook questions (Python focus)

Jean Bigboute jeanbigboute at gmail.com
Sat Jan 31 22:41:41 EST 2015

On Sat, Jan 31, 2015 at 10:00 AM,  <ipython-dev-request at scipy.org> wrote:

> Message: 4
> Date: Fri, 30 Jan 2015 15:48:59 -0800
> From: Thomas Kluyver <takowl at gmail.com>
> Subject: Re: [IPython-dev] Two basic Notebook questions (Python focus)

> On 30 January 2015 at 15:26, Jean Bigboute <jeanbigboute at gmail.com> wrote:
>> b) Is it possible to pass arguments to a magic function?
>> e.g.
>> import inspect
>> print inspect.getsource(function)
> This is probably easiest to do in a plain Python function. Create a file
> ~/.ipython/profile_default/startup/printsource.py (which IPython will
> automatically run when it starts, and put in it:
> import inspect
> def source(func)
>     print inspect.getsource(function)
> Now you can just type 'source(f)' to see a function in your notebook. Be
> aware, though, that if you share that notebook, other people won't have the
> source() function defined. You could also define it at the top of the
> notebook if you prefer.
> Thomas

I tried this on Anaconda and Canopy without success. (I also included
a colon at the end of the def source statement.

The code never loaded into the Notebook interface.

On Anaconda:
I then tried plain ipython (no notebook) and got the  error shown below.

I systematically deleted lines in the startup file and eventually had
just a blank file.  Error still results.

The Canopy  distribution is on my work machine so I don't know what
pure ipython would have done on it.

[TerminalIPythonApp] WARNING | Error in loading extension: kernmagic
Check your config files in /{PATH}/.ipython/profile_default
ImportError                               Traceback (most recent call last)
in load_extension(self, module_str)
     96             if module_str not in sys.modules:
     97                 with prepended_to_syspath(self.ipython_extension_dir):
---> 98                     __import__(module_str)
     99             mod = sys.modules[module_str]
    100             if self._call_load_ipython_extension(mod):

ImportError: No module named kernmagic

More information about the IPython-dev mailing list