Is there a way to convert Mathematica Notebook files (.nb) to Jupyter files (.ipynb) without using Mathematica?
Is there a free online utility or other piece of software that can do this?
$\begingroup$
$\endgroup$
5
-
$\begingroup$ This might be better asked on Stack Overflow? Unless you don't mind a solution that uses the free Wolfram Engine. Otherwise I think people might prefer being able to use the Mathematica language. $\endgroup$– b3m2a1Commented Aug 13, 2019 at 19:41
-
2$\begingroup$ @b3m2a1 I assumed that OP meant creating Jupyter notebooks that still contain WL code and would be used with the free wolfram engine. $\endgroup$– SzabolcsCommented Aug 14, 2019 at 8:51
-
3$\begingroup$ Jupyter notebooks are just JSON files, so at least grabbing the input cell text and placing that in an ipynb should be quite feasible, and not too hard. Converting other stuff is (much) more trouble, but still feasible. I don't have time for this, but if anyone is willing to spend and afternoon or two, it should be possible to do this. $\endgroup$– SzabolcsCommented Aug 14, 2019 at 8:53
-
$\begingroup$ Any updates with this? I'm trying to do the same thing. I have a bunch of old Mathematica notebooks that I want to use with Jupyter + Wolfram engine. $\endgroup$– ThatsRightJackCommented Sep 29, 2022 at 22:18
-
$\begingroup$ @ThatsRightJack No. $\endgroup$– GeremiaCommented Sep 29, 2022 at 23:39
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
WolframEngine is free. You can use the nb2ipynb
WolframScript:
nb2ipynb = Module[{
cellF = {
"cell_type" -> "code",
"execution_count" -> 1,
"metadata" -> <||>,
"outputs" -> {<|"name" -> "stdout",
"output_type" -> "stream",
"text" -> StringRiffle[ToString /@ {##2}, "\n"]|>},
"source" -> ToString /@ List @@ HoldForm /@ (#1/.Null -> "\n\n")
}&,
ipynbF = {
"cells" -> cellF @@@ #,
"metadata" -> {"kernelspec" -> {"display_name" -> "JWLS_2",
"language" -> "text",
"name" -> "jwls_2"},
"language_info" -> {"codemirror_mode" -> "mathematica",
"file_extension" -> ".wl",
"mimetype" -> "text/x-mathematica",
"name" -> "WolframScript"}},
"nbformat" -> 4,
"nbformat_minor" -> 2
}&,
nb = NotebookImport[# _,"FlattenCellGroups" -> False]~
DeleteCases~ HoldComplete[Null]},
Export[FileBaseName@#<>".ipynb", ipynbF@nb, "JSON"]
]&
Usage: nb2ipynb@"your_notebook.nb"
However, I'm getting this issue.
Also, you can use WolframLanguageForJupyter to interact with WolframEngine in a Jupyter (*.ipynb) notebook.