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.
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.
Using a command-line interfaceNotebooks can be executed from your terminal using the run subcommand.
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).
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.
You can access environmental variables instead. I have yet to come across a way to use command line arguments directly.
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
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