-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document JPY_SESSION_NAME environment variable, which contains current notebook's file path #16282
Comments
If you are using the latest versions of IPython/ipykernel and jupyter-serer, then there is an environment variable called import os
__ipynb_file__ = os.environ['JPY_SESSION_NAME'] In general, Jupyter works with a variety of kernels, not only with Python, so injecting a runtime variable is rather hard or even impossible to do for all kernels consistently (for example, this may be invalid variable name in some languages). |
As per above, this is incorrect. The problem is that this is not documented in JupyterLab documentation. I think it should be as a hint given how frequent this question is (and this issue is probably a duplicate). |
Thanks for the answer! |
I do get |
Thanks for pointing out, it seems that my dependencies are outdated. Updating them solves the problem. |
__ipynb_file__
global variable just like __vsc_ipynb_file__
in VisualStudio Code
Previous discussion (thanks @krassowski ) — #8012 (comment) |
Problem
Currently there is no official way of retrieving the notebook's file path dynamically during runtime. Although a package called ipynbname is created for this purpose, it is somehow restrictive and doesn't work under all scenarios (for example, it doesn't work if the jupyterlab is running behind a proxy).
Proposed Solution
VisualStudio Code Jupyter extension implemented a mechanism similar to
__file__
in pure python script. The file path of current running notebook is saved to a global variable__vsc_ipynb_file__
. It would be really helpful if jupyterlab can support a similar mechanism by saving the file path to__ipynb_file__
or something similar.Additional context
See microsoft/vscode-jupyter#8531
The text was updated successfully, but these errors were encountered: