Anyways to get the Jupyter notebook filename from PyCharm

I tried several ways recommended by Gemini but none of them work:

notebook_path = os.environ.get('JPY_SESSION_NAME')

Does not return the filename.

ipynbname package only works for the Jupyter notebooks running in the browser.

When I look into this workaround for VS code I discovery that PyCharm only has the directory path of the file, not the filename: ip.user_ns["_dh"][0]

I was trying to modify the file. So that Python can find the file under the directory with latest modified timestamp, but the PyCharm auto save does not triggered until the python code in a cell finishs execution.

There were also other ways recommended by Gemini to hack the Jupyter's API, but failed. So are there any other ways to get the Jupyter notebook filename from PyCharm?

 

Thanks a lot!

0

Please sign in to leave a comment.