I would like to programmatically run a jupyter notebook cell containing import statements and use the packages imported after opening the notebook and not just convert the output to a new ipython notebook.
Currently, I am using nbconvert to execute a pre-created Jupyter notebook. The steps taken to execute the notebook are as following -
jupyter nbconvert --execute --inplace test.ipynb
Code to create new notebook -
import nbformat as nbf
nb = nbf.v4.new_notebook()
nb['cells'] = [nbf.v4.new_markdown_cell(text),nbf.v4.new_code_cell(code,metadata={'editable':False,'deletable':False}) ]
nbf.write(nb, 'test.ipynb')
The code block in the notebook cell contains -
import pandas as pd
import numpy as np
import matplotlib as plt
%pylab inline
hist(normal(size=2000), bins=50)
The output cell displays the histogram as expected. However, I am unable to use the packages imported after opening the notebook. Is there a way to execute the notebook in command line and then use the imported packages after opening the notebook without having to manually run the cell again ?