4
$\begingroup$

I'm trying to execute a .ipynb from Mathematica.

I tried this code (*Import the Jupyter notebook file*)nb = Import["/Users/y/x.ipynb", "NB"]; (*Execute the notebook*) NotebookEvaluate[nb]

But it doesn't work. Anyone know how to run a Python Jupyter Book .ipynb File From Mathematica?

Thanks

I converted the file to .py, but that still doesn't help.

ExternalEvaluate["Python", "2+2"]

Even the above simple code results in the following error

ExternalEvaluate::help: For help configuring the Python evaluator, see Configure Python for ExternalEvaluate.

ExternalEvaluate::noinstall: No valid installations for system Python were found with the options specified.

$\endgroup$
5
  • 1
    $\begingroup$ What does the Jupyter notebook contain? Python code? Mathematica code? Something else? Have you considered exporting the notebook contents to a script file using Jupyter itself, and executing the script instead? Note that notebooks are designed to be used interactively, not to be executed as a self-contained script/program, so if you plan to run the code as a script, it's a good idea to refactor it into a proper script. $\endgroup$
    – Szabolcs
    Commented Jan 16, 2023 at 9:30
  • 1
    $\begingroup$ There also seem to be two distinct question here, which should be separated: (1) how to deal with Jupyter notebooks (2) how to configure ExternalEvaluate to work with Python reference.wolfram.com/language/workflow/… But if you just want to run a script, why don't you do that directly instead of involving ExternalEvaluate? ExternalEvaluate would be useful to bring Python data to Mathematica in a structured form. $\endgroup$
    – Szabolcs
    Commented Jan 16, 2023 at 9:41
  • 1
    $\begingroup$ It seems to me that in order to be able to provide an answer that will be useful to you, this question needs to be both more focused on a specific task, and explain that task (and the motivation) in more detail. $\endgroup$
    – Szabolcs
    Commented Jan 16, 2023 at 9:43
  • $\begingroup$ It is a Python script. I just want something that does this "{Export["x.csv",list], execute python script/Jupyter notebook, Import[...]]}[[3]] $\endgroup$ Commented Jan 16, 2023 at 18:27
  • 1
    $\begingroup$ It sounds like you don't need to record any output from running the code in the Jupyter notebooks. It just processes some data in an excel file that you export separately, and writes the result into another file? I think the easiest solution for you will be to run the Python code by invoking python with RunProcess. It seems that the notebook can be executed directly like this: stackoverflow.com/a/35572827/695132 (the jupyter command can also be run using RunProcess). I hope this helps. $\endgroup$
    – Szabolcs
    Commented Jan 17, 2023 at 7:25

1 Answer 1

2
$\begingroup$

You first command didn't work, because Import[path, "NB"] expects a file in Wolfram System notebook format, not Python format as described here.

For you second attempt, you should first configure python as described here (and suggested by the error message you quoted).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.