Reputation: 23
I'm trying to get the path of the current Jupyter notebook, while using VSCode.
I tried all of the solutions in this post but none of them are working in VSCode. I can get them to work through Jupyterlab.
When I try the solutions that involve a %%javascript magic command, that cell will execute successfully, but the kernel is not updated with the variable containing the notebook name.
Upvotes: 1
Views: 1801
Reputation: 1721
Or if you do not want the extension, the the filename, then try using pathlib.
from pathlib import Path
Path(globals()['__vsc_ipynb_file__']).stem
Upvotes: 0
Reputation: 166
Please try with this fix. This fix may vary from OS to OS. Follow me for more GitHub LinkedIn
import os
os.path.basename(globals()['__vsc_ipynb_file__'])
Upvotes: 10
Reputation: 9451
If you know the current opened notebook's filename, how about trying this method:
import os
notebook_path = os.path.abspath("a.ipynb")
print(notebook_path)
Upvotes: 0