Open
Description
When I execute a notebook in Jupyter Lab that uses the __session__
variable to resolve the path to the notebook, it works.
When I execute such a notebook via nbconvert --execute
, it fails with NameError: name __session__ is not defined
:
❯ jupyter nbconvert tmp.ipynb --to html --execute
[NbConvertApp] Converting notebook tmp.ipynb to html
Traceback (most recent call last):
File "/opt/conda/bin/jupyter-nbconvert", line 10, in <module>
sys.exit(main())
^^^^^^
File "/opt/conda/lib/python3.12/site-packages/jupyter_core/application.py", line 283, in launch_instance
super().launch_instance(argv=argv, **kwargs)
File "/opt/conda/lib/python3.12/site-packages/traitlets/config/application.py", line 1075, in launch_instance
app.start()
File "/opt/conda/lib/python3.12/site-packages/nbconvert/nbconvertapp.py", line 420, in start
self.convert_notebooks()
File "/opt/conda/lib/python3.12/site-packages/nbconvert/nbconvertapp.py", line 597, in convert_notebooks
self.convert_single_notebook(notebook_filename)
File "/opt/conda/lib/python3.12/site-packages/nbconvert/nbconvertapp.py", line 563, in convert_single_notebook
output, resources = self.export_single_notebook(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/nbconvertapp.py", line 487, in export_single_notebook
output, resources = self.exporter.from_filename(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/exporters/templateexporter.py", line 390, in from_filename
return super().from_filename(filename, resources, **kw) # type:ignore[return-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/exporters/exporter.py", line 201, in from_filename
return self.from_file(f, resources=resources, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/exporters/templateexporter.py", line 396, in from_file
return super().from_file(file_stream, resources, **kw) # type:ignore[return-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/exporters/exporter.py", line 220, in from_file
return self.from_notebook_node(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/exporters/html.py", line 278, in from_notebook_node
html, resources = super().from_notebook_node(nb, resources, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/exporters/templateexporter.py", line 412, in from_notebook_node
nb_copy, resources = super().from_notebook_node(nb, resources, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/exporters/exporter.py", line 154, in from_notebook_node
nb_copy, resources = self._preprocess(nb_copy, resources)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/exporters/exporter.py", line 353, in _preprocess
nbc, resc = preprocessor(nbc, resc)
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/preprocessors/base.py", line 48, in __call__
return self.preprocess(nb, resources)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbconvert/preprocessors/execute.py", line 103, in preprocess
self.preprocess_cell(cell, resources, index)
File "/opt/conda/lib/python3.12/site-packages/nbconvert/preprocessors/execute.py", line 124, in preprocess_cell
cell = self.execute_cell(cell, index, store_history=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/jupyter_core/utils/__init__.py", line 165, in wrapped
return loop.run_until_complete(inner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/site-packages/nbclient/client.py", line 1062, in async_execute_cell
await self._check_raise_for_error(cell, cell_index, exec_reply)
File "/opt/conda/lib/python3.12/site-packages/nbclient/client.py", line 918, in _check_raise_for_error
raise CellExecutionError.from_cell_and_msg(cell, exec_reply_content)
nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell:
------------------
__session__
------------------
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[1], line 1
----> 1 __session__
NameError: name '__session__' is not defined
Works in Jupyter Lab:

Metadata
Metadata
Assignees
Labels
No labels