nbconvert (a jupyter tool for notebook conversion) allows you to do this without any extra packages:
Just go to your terminal and type
$ jupyter nbconvert –to notebook –inplace –execute mynotebook.ipynb
Source
(Thanks Stephan for suggesting the --inplace flag)
NOTE: This said, I’d try to convert everything you need to a proper script. Jupyter notebooks are thought to use for exploring and sharing results, and not as a replacement of traditional programs.