2

I am running a Julia script in a Jupyter Notebook on a remote host by using the following command in a jupyter-environment

jupyter nbconvert --to notebook --execute my_notebook.ipynb

which works fine. However, if I try to pass arguments to the Jupyter Notebook with the intention to be finally passed to the Julia script I fail. My question is how to do it?

  • To pass arguments to the Jupyter Notebook I modified the above command to
jupyter nbconvert --to notebook --execute my_notebook.ipynb arg1 arg2 arg3
  • Also, in the Julia script I try to recover the arguments (which are supposed to be small enough integers) via
x1 = parse(Int16, ARGS[1])
x2 = parse(Int16, ARGS[2])
x3 = parse(Int16, ARGS[3])

which doesn't work.

  • I tried to understand what is in ARGS, but I can't decipher what it means. The output of
println(ARGS)

included in the Julia script is

"/tmp/tmp8vuj5f79.json"

Coming back to the second bullet point, a few errors occur since ARGS[1] obviously can't be converted to an integer.

  • Another error which occurs when passing the arguments to the Jupyter Notebook execution is
[NbConvertApp] WARNING | pattern 'arg1' matched no files
[NbConvertApp] WARNING | pattern 'arg2' matched no files
[NbConvertApp] WARNING | pattern 'arg3' matched no files

I might be approaching the problem from a completely wrong perspective, so any help would be very much appreciated!

mbejan
  • 21
  • 2

1 Answers1

0

It looks like it's not possible to pass in command-line arguments to --executed notebooks.
The WARNING | pattern 'arg1' matched no files messages indicate that these arguments are seen by nbconvert as additional files to convert, not as arguments to the notebook.

The common suggestion is to use environment variables instead.

X=12 Y=5 Z=42 jupyter nbconvert --to notebook --execute my_notebook.ipynb

which you can then access from within the notebook as ENV["X"], ENV["Y"], and ENV["Z"].

Sundar R
  • 13,776
  • 6
  • 49
  • 76