Skip to content
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

Compatibility with VS Code #17

Closed
jbogar opened this issue Sep 15, 2022 · 2 comments
Closed

Compatibility with VS Code #17

jbogar opened this issue Sep 15, 2022 · 2 comments

Comments

@jbogar
Copy link

jbogar commented Sep 15, 2022

When the notebook runs in VS Code, ipynbname throws an error, but it works fine if the notebook is ran with jupyter notebook from terminal.

import ipynbname
ipynbname.path()

produces:

FileNotFoundError                         Traceback (most recent call last)
/Users/jbogar/dummy_notebook.ipynb Cell 2 in <cell line: 2>()
      [1](vscode-notebook-cell:/Users/jbogar/dummy_notebook.ipynb#W1sZmlsZQ%3D%3D?line=0) import ipynbname
----> [2](vscode-notebook-cell:/Users/jbogar/dummy_notebook.ipynb#W1sZmlsZQ%3D%3D?line=1) ipynbname.path()

File ~/opt/miniconda3/lib/python3.8/site-packages/ipynbname/__init__.py:93, in path()
     91     root_dir = Path(srv.get('root_dir') or srv['notebook_dir'])
     92     return root_dir / path
---> 93 raise FileNotFoundError(FILE_ERROR.format('path'))

FileNotFoundError: Can't identify the notebook path.

environment:

python == 3.8.13
ipynbname == 2021.3.2
ipykernel == 6.9.1
VS Code version == 1.70.1

Is that an expected behavior? Any idea why does it happen or how to fix it?

Thanks

@antdking
Copy link

We're facing similar problems, though it's inconsistent (current theory is the server launches differently when running on Linux, but we don't have the experience to confirm).

As a workaround, the path is exposed through a variable

snippet for extracting the path:

from IPython import get_ipython
ip = get_ipython()
path = None
if '__vsc_ipynb_file__' in ip.user_ns:
    path = ip.user_ns['__vsc_ipynb_file__']

path

@msm1089
Copy link
Owner

msm1089 commented Apr 9, 2023

Thanks @antdking - hope that helps others using VS Code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants