[IPython-dev] executing notebooks locally

Nathan Goldbaum nathan12343 at gmail.com
Wed Jan 29 12:51:35 EST 2014


Have you seen runipy?

https://github.com/paulgb/runipy/

On Wed, Jan 29, 2014 at 9:42 AM, Toby Burnett <tburnett at myuw.net> wrote:
> I'm using IPython notebooks to document code, in which cell output reflects
> the machine it was run on. I want to export the notebooks to a different
> machine, and rerun them to reflect that machine's environment. That is, the
> equivalent of starting a server, loading each notebook in a browser, then
> clicking  Cell |Run All.  Obviously it would be more convenient to just run
> a local script to do this.
>
>
>
> There seems to be no such option in the ipython notebook command. But I
> found this on stackoverflow:
>
> http://stackoverflow.com/questions/19640280/execute-another-ipython-notebook-in-a-separate-namespace
>
>
>
> My attempt  to do this is:
>
>
>
> from IPython.nbformat import current
>
> ip = get_ipython()
>
> with open('Untitled1.ipynb') as f:
>
>     nb = current.read(f, 'json')
>
> code_cells = filter( lambda x: x.cell_type=='code', nb.worksheets[0].cells)
>
> map(ip.run_cell, code_cells)
>
>
>
> But with a result
>
> ---------------------------------------------------------------------------
>
> AttributeError                            Traceback (most recent call last)
>
> <ipython-input-16-530ade14060f> in <module>()
>
>       4     nb = current.read(f, 'json')
>
>       5 code_cells = filter( lambda x: x.cell_type=='code',
> nb.worksheets[0].cells)
>
> ----> 6 map(ip.run_cell, code_cells)
>
>
>
> /phys/users/tburnett/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc
> in run_cell(self, raw_cell, store_history, silent, shell_futures)
>
>    2642           __future__ imports are not shared in either direction.
>
>    2643         """
>
> -> 2644         if (not raw_cell) or raw_cell.isspace():
>
>    2645             return
>
>    2646
>
>
>
> /phys/users/tburnett/anaconda/lib/python2.7/site-packages/IPython/utils/ipstruct.pyc
> in __getattr__(self, key)
>
>     147             result = self[key]
>
>     148         except KeyError:
>
> --> 149             raise AttributeError(key)
>
>     150         else:
>
>     151             return result
>
>
>
> AttributeError: isspace
>
>
>
> Indeed the NotebookNode object does not have an isspace function. (This is
> 2.0-dev.)
>
> Any thoughts?
>
>
>
> --Toby
>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>



More information about the IPython-dev mailing list