Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch execute iPython Notebook with command line argument?

I'm using nbconvert to execute an iPython notebook via the command line (as in this answer):

ipython nbconvert --to=html --ExecutePreprocessor.enabled=True RunMe.ipynb

Is it possible to pass command line arguments to be accessed from within the notebook (like sys.argv)?

This would let me reuse the same notebook in different contexts.

like image 730
DavidC Avatar asked May 06 '15 15:05

DavidC


People also ask

How do I run IPython notebook from command-line?

3.1. Click on spotlight, type terminal to open a terminal window. Enter the startup folder by typing cd /some_folder_name . Type jupyter notebook to launch the Jupyter Notebook App The notebook interface will appear in a new browser window or tab.

Can I execute Jupyter Notebook from command-line?

Using a command-line interfaceNotebooks can be executed from your terminal using the run subcommand.

How do I run a Jupyter Notebook script from command prompt?

How to open Jupyter Notebook. To launch a Jupyter notebook, open your terminal and navigate to the directory where you would like to save your notebook. Then type the command jupyter notebook and the program will instantiate a local server at localhost:8888 (or another specified port).

How do I run a batch file in Jupyter Notebook?

bat from the Desktop. Right click to change property of the link in the tab link. In Target you enter: %UserProfile%\<Anaconda or miniconda3>\Scripts\activate. bat <your-env-name> && @CALL jupyter lab (when you do not know your environment name you can check them in the file environments.


2 Answers

You can access environmental variables instead. I have yet to come across a way to use command line arguments directly.

like image 60
nitind Avatar answered Sep 29 '22 12:09

nitind


This is my attempt at a single module for argument parsing in Python scripts and Jupyter notebooks. It only supports minimalist key=value style arguments but meets my needs.

I nbconvert it to a Python script named Args.py and use it as shown.

Then I can batch run a notebook like:

jpn mynotebook limit=5 assignment=A2

like image 29
GaryBishop Avatar answered Sep 29 '22 14:09

GaryBishop