[IPython-User] Kernprof in ipython 0.11?

Ariel Rokem arokem@gmail....
Sat Mar 31 20:58:13 CDT 2012


Hi Robert and all,

On Wed, Sep 21, 2011 at 4:06 PM, Robert Kern <robert.kern@gmail.com> wrote:
> On 9/20/11 9:08 AM, Johann Cohen-Tanugi wrote:
>> Hi Robert,
>>
>> On 09/02/2011 04:08 AM, Robert Kern wrote:
>>> On 9/1/11 7:07 AM, reckoner wrote:
>>>> Will the exceptional kernprof module make it into IPython 0.11 as a magic?
>>> Not distributed *with* IPython, no. It's easy to configure IPython 0.11 to add
>>> its %lprun magic, though. Just make a file line_profiler_ext.py in your
>>> ~/.ipython/extensions/ directory:
>>>
>>>      import line_profiler
>>>      def load_ipython_extension(ip):
>>>          ip.define_magic('lprun', line_profiler.magic_lprun)
>>>
>>> Then add it to your list of extensions in your ipython_config.py:
>>>
>>> # A list of dotted module names of IPython extensions to load.
>>> c.TerminalIPythonApp.extensions = [
>>>        'line_profiler_ext',
>>> ]
>>>
>> I just tried that, and I get :
>> In [1]: %lprun -f polylog.polylog(2,0.5)
>> ---------------------------------------------------------------------------
>> ImportError                               Traceback (most recent call last)
>> /home/cohen/<ipython-input-1-4a7604b1bbac>  in<module>()
>> ---->  1 get_ipython().magic(u"lprun -f polylog.polylog(2,0.5)")
>>
>> /usr/local/lib/python2.6/dist-packages/ipython-0.11-py2.6.egg/IPython/core/interactiveshell.pyc
>> in magic(self, arg_s, next_input)
>>      1892                 self._magic_locals = sys._getframe(1).f_locals
>>      1893             with self.builtin_trap:
>> ->  1894                 result = fn(magic_args)
>>      1895             # Ensure we're not keeping object references around:
>>
>>      1896             self._magic_locals = {}
>>
>> /usr/local/lib/python2.6/dist-packages/line_profiler-1.0b2-py2.6-linux-i686.egg/line_profiler.pyc
>> in magic_lprun(self, parameter_s)
>>       166     """
>>       167     # Local import to avoid hard dependency.
>>
>> -->  168     from IPython.genutils import page
>>       169     from IPython.ipstruct import Struct
>>       170     from IPython.ipapi import UsageError
>>
>> ImportError: No module named genutils
>
> Oh, I guess I need to update the imports to match the refactoring, then.
> Bother.
>

Does anyone know whether this works with 0.12 and with the current
config layout? If anyone has done this successfully, where did you put
the aforementioned line_profiler_ext.py file?

Thanks,

Ariel


More information about the IPython-User mailing list