Skip to content
Advertisement

Get current jupyter-lab notebook name [for Jupyter-lab version 2.1 and 3.0.1 and notebook version >6.0.3)

Problem

Hi all,

As my title suggested it, I would like to get access to the notebook name (in jupyter-lab) as a variable. So I could reuse it in the notebook itself (for example to name some figure files generated in the notebook).

I saw that a similar issue was opened years ago [see here]. However I didnt find a satisfactory answer.

I like the simplicity of the answer suggested by @bill:

JavaScript
JavaScript

However, it doesn’t work for me. I got this warning the first time I execute the first cell:

JavaScript
JavaScript
JavaScript

Then if I rerun the cell again, I don’t have the warning message anymore but the variable currentNotebook is still empty. (I run the cell sequentially, I didn’t do a ‘Run All Cells’).

Configuration details

My Jupyter version is

JavaScript

I am using my notebook mostly for python code.


Edit 27/01/2021

@juan solution [here], using ipynbname is working for

JavaScript

but this solution is still not working for jupyter lab : 3.0.1


Edit 28/01/2021

ipynbname is now working for jupyter 3

More details about it [here]

Advertisement

Answer

As an alternative you can use the following library: ipynbname

JavaScript

This worked for me and the solution is quite straightforward.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement