Ask Your Question
1

scripting (jupyter) notebooks

asked 2017-03-09 11:27:32 +0100

Is there a way to execute a notebook file from the command line and automatically run all cells?

I am looking for something like

sage -n jupyter --no-browser --script test1.ipynb 

however, --script is deprecated and --no-browser doesn't stop sage from opening a browser window for me. Worse yet, the cells in the notebook are not executed automatically either.

Background: My aim is to automatically run a set of different sage notebooks (which are basically scripts to generate data files) in a directory, similar to how you would compile various source files to binaries. The notebooks are a collaborative effort and in a version control system and every developer would be able to generate those data files locally on their machine by running some shell script or through a Makefile.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2017-03-10 01:04:20 +0100

vdelecroix gravatar image

updated 2017-03-10 09:33:11 +0100

This is at least one possibility

$ sage -sh
$ jupyter convert --to='python' --output-dir=/tmp test1.ipynb
$ sage /tmp/test1.py

However, I am not sure how much the conversion is reliable. Why not storing your scripts as python files instead of notebooks?

edit flag offensive delete link more

Comments

I guess jupyter bconvert should be replaced with jupyter bconvert

tmonteil gravatar imagetmonteil ( 2017-03-10 08:12:37 +0100 )edit

Excellent, that is great. It is nbconvert instead of convert for me, but that seems to do the trick. It does not seem to convert expressions like x^2 to x**2, but I can live with that. In fact, I now see there's an --execute option to nbconvert which (aside from producing e.g. a python file) is what I wanted in the first place.

To answer your question: I see the notebooks as "source code", as everything else can be generated from them, like the python files as you suggest. But then working with the python files is not as nice as with the notebooks, so I'll keep the notebooks under version control instead.

Björn gravatar imageBjörn ( 2017-03-10 10:09:31 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-03-09 11:27:32 +0100

Seen: 1,102 times

Last updated: Mar 10 '17