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

KeyError (0) #24

Open
mcartagenah opened this issue May 23, 2022 · 8 comments
Open

KeyError (0) #24

mcartagenah opened this issue May 23, 2022 · 8 comments

Comments

@mcartagenah
Copy link

I'm trying to use euporie in iTerm2, after enabling CSI-u mode I can use Ctrl+Enter but I'm getting:

An error ocurred:
KeyError(0)
@joouha
Copy link
Owner

joouha commented May 25, 2022

Hello,

I've just tested this on iTerm2 but can't reproduce the error.

Could you run euporie with debugging enabled and recreate the error, then post the debug log output?

You can save the log output to a file and enable debugging as follows:

euporie --log-file=log.log --debug edit my-notebook.ipynb

Thanks

@mcartagenah
Copy link
Author

2022-05-28 17:17:45 DEBUG   [euporie.terminal.send:156] Sending query '\x1b]11;?\x1b\\' for ForegroundColor
2022-05-28 17:17:45 DEBUG   [euporie.terminal.send:156] Sending query '\x1b]10;?\x1b\\' for BackgroundColor
2022-05-28 17:17:45 DEBUG   [euporie.terminal.send:156] Sending query '\x1b[14t' for PixelDimensions
2022-05-28 17:17:45 DEBUG   [euporie.terminal.send:156] Sending query '\x1b[c' for SixelGraphicsStatus
2022-05-28 17:17:45 DEBUG   [euporie.terminal.send:156] Sending query '\x1b_Gi=4294967295,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\' for KittyGraphicsStatus
2022-05-28 17:17:45 DEBUG   [euporie.terminal._handle_response:139] Got terminal response for 'PixelDimensions'
2022-05-28 17:17:45 DEBUG   [euporie.terminal._handle_response:139] Got terminal response for 'SixelGraphicsStatus'
2022-05-28 17:17:45 INFO    [euporie.app.base.open_file:332] Opening file notebook.ipynb
2022-05-28 17:17:45 DEBUG   [euporie.tabs.notebook.__init__:80] Loading notebooks notebook.ipynb
2022-05-28 17:17:45 DEBUG   [euporie.kernel.start_:228] Starting kernel
2022-05-28 17:17:45 DEBUG   [euporie.kernel.start_:238] Started kernel
2022-05-28 17:17:45 DEBUG   [euporie.kernel.start_:243] Waiting for kernel to become ready
2022-05-28 17:17:46 DEBUG   [euporie.kernel.start_:252] Kernel e9395079-ab3d-461d-b3b7-d4928cddc45d ready
2022-05-28 17:17:46 DEBUG   [euporie.kernel.poll:199] Waiting for shell messages
2022-05-28 17:17:46 DEBUG   [euporie.kernel.poll:201] Waiting for next shell message
2022-05-28 17:17:46 DEBUG   [euporie.kernel.poll:199] Waiting for iopub messages
2022-05-28 17:17:46 DEBUG   [euporie.kernel.poll:201] Waiting for next iopub message
2022-05-28 17:17:46 DEBUG   [euporie.kernel.poll:199] Waiting for stdin messages
2022-05-28 17:17:46 DEBUG   [euporie.kernel.poll:201] Waiting for next stdin message
2022-05-28 17:17:46 DEBUG   [euporie.tabs.notebook.check_kernel:415] Kernel status is 'idle'
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:293] Waiting for shell response to _2946_1
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:297] Waiting for event on shell channel
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:293] Waiting for iopub response to _2946_1
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:297] Waiting for event on iopub channel
2022-05-28 17:17:46 DEBUG   [euporie.kernel.poll:201] Waiting for next iopub message
2022-05-28 17:17:46 DEBUG   [euporie.kernel.poll:201] Waiting for next shell message
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:306] Event occurred on channel iopub
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:309] Got iopub response:
type = 'status', content = '{'execution_state': 'busy'}'
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:297] Waiting for event on iopub channel
2022-05-28 17:17:46 DEBUG   [euporie.kernel.poll:201] Waiting for next iopub message
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:306] Event occurred on channel shell
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:309] Got shell response:
type = 'kernel_info_reply', content = '{'status': 'ok', 'protocol_version': '5.3', 'implementation': 'ipython', 'implementation_version': '7.14.0', 'language_info': {'name': 'python', 'version': '3.8.2', 'mimetype': 'text/x-python', 'codemirror_mode': {'name': 'ipython', 'version': 3}, 'pygments_lexer': 'ipython3', 'nbconvert_exporter': 'python', 'file_extension': '.py'}, 'banner': "Python 3.8.2 (default, May  6 2020, 17:03:24) \nType 'copyright', 'credits' or 'license' for more information\nIPython 7.14.0 -- An enhanced Interactive Python. Type '?' for help.\n", 'help_links': [{'text': 'Python Reference', 'url': 'https://docs.python.org/3.8'}, {'text': 'IPython Reference', 'url': 'https://ipython.org/documentation.html'}, {'text': 'NumPy Reference', 'url': 'https://docs.scipy.org/doc/numpy/reference/'}, {'text': 'SciPy Reference', 'url': 'https://docs.scipy.org/doc/scipy/reference/'}, {'text': 'Matplotlib Reference', 'url': 'https://matplotlib.org/contents.html'}, {'text': 'SymPy Reference', 'url': 'http://docs.sympy.org/latest/index.html'}, {'text': 'pandas Reference', 'url': 'https://pandas.pydata.org/pandas-docs/stable/'}]}'
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:318] Stopping waiting for responses to e54a9589-1862f2de4b4481406235975a_2946_1 on shell channel
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:306] Event occurred on channel iopub
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:309] Got iopub response:
type = 'status', content = '{'execution_state': 'idle'}'
2022-05-28 17:17:46 DEBUG   [euporie.kernel.await_rsps:318] Stopping waiting for responses to e54a9589-1862f2de4b4481406235975a_2946_1 on iopub channel
2022-05-28 17:17:47 ERROR   [euporie.app.edit._handle_exception:524] An unhandled exception occurred
Traceback (most recent call last):
  File "/Users/mcartagenah/.pyenv/versions/3.8.2/lib/python3.8/asyncio/events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/mcartagenah/.pyenv/versions/3.8.2/envs/mich/lib/python3.8/site-packages/prompt_toolkit/input/vt100.py", line 173, in callback_wrapper
    callback()
  File "/Users/mcartagenah/.pyenv/versions/3.8.2/envs/mich/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 710, in read_from_input
    self.key_processor.process_keys()
  File "/Users/mcartagenah/.pyenv/versions/3.8.2/envs/mich/lib/python3.8/site-packages/euporie/key_binding/key_processor.py", line 104, in process_keys
    self._process_coroutine.send(key_press)
  File "/Users/mcartagenah/.pyenv/versions/3.8.2/envs/mich/lib/python3.8/site-packages/prompt_toolkit/key_binding/key_processor.py", line 185, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "/Users/mcartagenah/.pyenv/versions/3.8.2/envs/mich/lib/python3.8/site-packages/prompt_toolkit/key_binding/key_processor.py", line 320, in _call_handler
    handler.call(event)
  File "/Users/mcartagenah/.pyenv/versions/3.8.2/envs/mich/lib/python3.8/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 124, in call
    result = self.handler(event)
  File "/Users/mcartagenah/.pyenv/versions/3.8.2/envs/mich/lib/python3.8/site-packages/euporie/commands/base.py", line 157, in _key_handler
    result = self.handler()
  File "/Users/mcartagenah/.pyenv/versions/3.8.2/envs/mich/lib/python3.8/site-packages/euporie/commands/notebook.py", line 81, in run_selected_cells_and_select_next_cell
    nb.run_selected_cells(advance=True)
  File "/Users/mcartagenah/.pyenv/versions/3.8.2/envs/mich/lib/python3.8/site-packages/euporie/tabs/notebook.py", line 791, in run_selected_cells
    cells[i].run_or_render()
KeyError: 0
2022-05-28 17:17:51 DEBUG   [euporie.tabs.notebook.really_close:880] Closing notebook 'notebook.ipynb'
2022-05-28 17:17:51 DEBUG   [euporie.kernel.stop:895] Stopping kernel e9395079-ab3d-461d-b3b7-d4928cddc45d (wait=False)
2022-05-28 17:17:51 DEBUG   [euporie.kernel.interrupt:845] Interrupting kernel e9395079-ab3d-461d-b3b7-d4928cddc45d

@joouha
Copy link
Owner

joouha commented May 31, 2022

Thanks!

I think I see what's happening, but I still don't understand why it's happening. It looks like cell 0 (the first cell) is selected, but when it is run no cell with index == 0 is found. Possibly the cell index saved in the cell object is getting out of sync with its position somehow.

I've attempted a fix for this in 546b545, but can't reproduce the error, so I'm not sure whether this will fix it.

  • Do you only get this error on a particular notebook, or does it occur with any notebook?
  • How many cells does the notebook have when this happens?
  • Which cell(s) are selected when you try and run them?

@mcartagenah
Copy link
Author

mcartagenah commented Jun 1, 2022

Hi, thank you for the fix, unfortunately I installed it through pip, maybe this weekend I install it from source to test it.

The problem is with any notebook, it has only 1 cell and it's selected, I tried adding more cells but the commands aren't working. Can you help me with how do I need to configure iterm?

@danielcs88
Copy link

danielcs88 commented May 26, 2023

I believe I have the same error.

Traceback

Traceback (most recent call last):
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/eventloop/utils.py", line 73, in schedule
    func()
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 476, in redraw
    self._redraw()
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 548, in _redraw
    self.context.copy().run(run_in_context)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 531, in run_in_context
    self.renderer.render(self, self.layout)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/core/renderer.py", line 411, in render
    self._cursor_pos, self._last_style = _output_screen_diff(
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/core/renderer.py", line 167, in _output_screen_diff
    new_max_line_len = min(width - 1, get_max_column_index(new_row, zwe_row))
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/core/renderer.py", line 121, in get_max_column_index
    {
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/core/renderer.py", line 124, in <setcomp>
    if cell.char != " " or style_string_has_style[cell.style]
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/renderer.py", line 306, in __missing__
    attrs = self.style_string_to_attrs[style_str]
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/renderer.py", line 284, in __missing__
    attrs = self.get_attrs_for_style_str(style_str)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/styles/style.py", line 397, in get_attrs_for_style_str
    return self._merged_style.get_attrs_for_style_str(style_str, default)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/styles/style.py", line 311, in get_attrs_for_style_str
    inline_attrs = _parse_style_str(part)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/styles/style.py", line 171, in _parse_style_str
    attrs = attrs._replace(color=parse_color(part))
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/styles/style.py", line 75, in parse_color
    raise ValueError("Wrong color format %r" % text)
ValueError: Wrong color format 'key'

Output from euporie-notebook --log-file=log.log --debug edit 10178_businesses_open_on_sunday.py

2023-05-24 21:25:04 ERROR   [euporie.notebook.app._handle_exception:289] An unhandled exception occurred
Traceback (most recent call last):
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/core/tabs/base.py", line 217, in init_kernel
    self.post_init_kernel()
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/notebook/tabs/edit.py", line 64, in post_init_kernel
    self.load()
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/notebook/tabs/edit.py", line 69, in load
    text = self.path.read_text()
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/pathlib.py", line 1134, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/pathlib.py", line 1119, in open
    return self._accessor.open(self, mode, buffering, encoding, errors,
FileNotFoundError: [Errno 2] No such file or directory: '/Users/daniel/Dropbox/Code/Data_Science/Strata-Scratch/edit'
2023-05-26 00:45:33 ERROR   [euporie.notebook.app._handle_exception:289] An unhandled exception occurred
Traceback (most recent call last):
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/core/tabs/base.py", line 217, in init_kernel
    self.post_init_kernel()
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/notebook/tabs/edit.py", line 64, in post_init_kernel
    self.load()
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/notebook/tabs/edit.py", line 69, in load
    text = self.path.read_text()
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/pathlib.py", line 1134, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/pathlib.py", line 1119, in open
    return self._accessor.open(self, mode, buffering, encoding, errors,
FileNotFoundError: [Errno 2] No such file or directory: '/Users/daniel/Dropbox/Code/Data_Science/Strata-Scratch/edit'
2023-05-26 00:46:37 WARNING [euporie.core.format.format_black:26] Error formatting code with black: invalid input

@joouha
Copy link
Owner

joouha commented May 30, 2023

Hi @danielcs88,

I think you're experiencing different errors to the ones above - do you mind creating a new issue?

For the first error (ValueError: Wrong color format 'key'), what steps are you doing before the error occurs?

The second one is beacuse you are running euporie-notebook edit <filename>, and euporie-notebook is trying to open a file called edit - you don't need the edit command.

@danielcs88
Copy link

@joouha

I created a new issue #79

@joouha
Copy link
Owner

joouha commented Jan 18, 2024

@mcartagenah is this still an issue with the latest version of euporie?

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