I am deploying a Python package, and I would like to run a simple test to see if all cells in my notebook will run without errors. I would like to test this via commandline as I have issues running a notebook in virtualenv
. Is there are simple command-line way to test this?
Note to the moderator: this question has been marked as a duplicate of How to run an .ipynb Jupyter Notebook from terminal? . However, this question was posted (asked Feb 18 '16 at 2:49) several days before that one (asked Feb 22 '16 at 3:35). At most, that post might be marked as a duplicate, and if deemed so, an appropriate action would be to merge the two questions, maintaining this, the original, as the master.
However, these questions may not be duplicates (the intent of the other author is unclear). Regardless, this question and it's answers specifically address executing cells within a jupyter notebook from the terminal, not simply converting notebooks to python files.
Windows File Explorer + Command Prompt Once you've entered your specific folder with Windows Explorer, you can simply press ALT + D, type in cmd and press Enter. You can then type jupyter notebook to launch Jupyter Notebook within that specific folder.
You can use the jupyter console -i command to run an interactive jupyter session in your terminal. From there you can run import <my_script.py> . Do note that this is not the intended use case of either jupyter or the notebook environment. You should run scripts using your normal python interpreter instead.
When you open a new Jupyter notebook, you'll notice that it contains a cell. Cells are how notebooks are structured and are the areas where you write your code. To run a piece of code, click on the cell to select it, then press SHIFT+ENTER or press the play button in the toolbar above.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With