ipynbname icon indicating copy to clipboard operation
ipynbname copied to clipboard

IndexError: list index out of range

Open laurentperrinet opened this issue 2 years ago • 4 comments

  • on a ubuntu box, I use the package to retrieve the name of a notebook using a cell like:
import ipynbname
datetag = ipynbname.name()
print('Running', ipynbname.path())
  • this is run through nbconvert with a command like:
jupyter nbconvert  --ExecutePreprocessor.timeout=0 --allow-errors --execute --to notebook --inplace 2022-04-06_Supervised_MC-B_V.ipynb
  • however I get the following error, the full trace I get is
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Input In [5], in <cell line: 2>()
      1 import ipynbname
----> 2 datetag = ipynbname.name()
      3 print('Running', ipynbname.path())

File ~/.local/lib/python3.8/site-packages/ipynbname/__init__.py:79, in name()
     75 def name() -> str:
     76     """ Returns the short name of the notebook w/o the .ipynb extension,
     77         or raises a FileNotFoundError exception if it cannot be determined.
     78     """
---> 79     _, path = _find_nb_path()
     80     if path:
     81         return path.stem

File ~/.local/lib/python3.8/site-packages/ipynbname/__init__.py:61, in _find_nb_path()
     59 def _find_nb_path() -> Union[Tuple[dict, PurePath], Tuple[None, None]]:
     60     try:
---> 61         kernel_id = _get_kernel_id()
     62     except (MultipleInstanceError, RuntimeError):
     63         return None, None  # Could not determine

File ~/.local/lib/python3.8/site-packages/ipynbname/__init__.py:37, in _get_kernel_id()
     34 """ Returns the kernel ID of the ipykernel.
     35 """
     36 connection_file = Path(ipykernel.get_connection_file()).stem
---> 37 kernel_id = connection_file.split('-', 1)[1]
     38 return kernel_id

IndexError: list index out of range
  • the version of my libraries are:
$ jupyter --version
Selected Jupyter core packages...
IPython          : 8.2.0
ipykernel        : 6.9.1
ipywidgets       : 7.6.5
jupyter_client   : 7.1.2
jupyter_core     : 4.9.2
jupyter_server   : 1.16.0
jupyterlab       : 3.3.2
nbclient         : 0.5.11
nbconvert        : 6.4.5
nbformat         : 5.3.0
notebook         : 6.4.8
qtconsole        : 5.2.2
traitlets        : 5.1.1

Any idea why this happens?

Thanks, Laurent

laurentperrinet avatar Apr 06 '22 16:04 laurentperrinet

I'm running into this too when running a notebook from the command-line

astrofrog avatar Mar 27 '23 09:03 astrofrog

same here, when running from papermill

SHuang-Broad avatar May 18 '23 16:05 SHuang-Broad