Skip to content

Convert .ipynb to .py

https://github.com/mwouts/jupytext

pip install jupytext --upgrade

or

conda install -c conda-forge jupytext

Command line conversion

The package provides a jupytext script for command line conversion between the various notebook extensions:

jupytext --to py notebook.ipynb                 # convert notebook.ipynb to a .py file
jupytext --to notebook notebook.py              # convert notebook.py to an .ipynb file with no outputs
jupytext --to notebook --execute notebook.md    # convert notebook.md to an .ipynb file and run it
jupytext --update --to notebook notebook.py     # update the input cells in the .ipynb file and preserve outputs and metadata
jupytext --set-formats ipynb,py notebook.ipynb  # Turn notebook.ipynb into a paired ipynb/py notebook
jupytext --sync notebook.ipynb                  # Update all paired representations of notebook.ipynb
jupytext --to notebook Nine.py 
jupytext --to py Nine.ipynb

rm /tmp/spec.txt
time runipy Nine.ipynb 
real	0m52.001s

rm /tmp/spec.txt
time python Nine.py
real	0m39.268s
Published inUncategorized

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *