joouha / euporie

Jupyter notebooks in the terminal
https://euporie.readthedocs.io
MIT License
1.54k stars 36 forks source link

Using chafa.py gives (Format Conversion Error) #71

Closed twrightsman closed 1 year ago

twrightsman commented 1 year ago

Migrating this to it's own issue from https://github.com/joouha/euporie/issues/67. Plotting with chafa.py installed gives a (Format Conversion Error).

screenshot showing euporie format conversion error

joouha commented 1 year ago

Please could you post a debug log?

You can create adebug log by running euporie as follows:

euporie-notebook --log-level=debug --log-file=log.log my-notebook.ipynb
twrightsman commented 1 year ago

Sure thing! See below:

2023-05-03 13:55:28 DEBUG   [euporie.core.terminal.send:115] Sending query '\x1bPtmux;\x1b\x1b]10;?\x1b\x1b\\\x1b\x1b]11;?\x1b\x1b\\\x1b\x1b]4;0;?\x1b\x1b\\\x1b\x1b]4;1;?\x1b\x1b\\\x1b\x1b]4;2;?\x1b\x1b\\\x1b\x1b]4;3;?\x1b\x1b\\\x1b\x1b]4;4;?\x1b\x1b\\\x1b\x1b]4;5;?\x1b\x1b\\\x1b\x1b]4;6;?\x1b\x1b\\\x1b\x1b]4;7;?\x1b\x1b\\\x1b\x1b]4;8;?\x1b\x1b\\\x1b\x1b]4;9;?\x1b\x1b\\\x1b\x1b]4;10;?\x1b\x1b\\\x1b\x1b]4;11;?\x1b\x1b\\\x1b\x1b]4;12;?\x1b\x1b\\\x1b\x1b]4;13;?\x1b\x1b\\\x1b\x1b]4;14;?\x1b\x1b\\\x1b\x1b]4;15;?\x1b\x1b\\\x1b\\' for Colors
2023-05-03 13:55:28 DEBUG   [euporie.core.terminal.send:115] Sending query '\x1b[14t' for PixelDimensions
2023-05-03 13:55:28 DEBUG   [euporie.core.terminal.send:115] Sending query '\x1bPtmux;\x1b\x1b[c\x1b\\' for SixelGraphicsStatus
2023-05-03 13:55:28 DEBUG   [euporie.core.terminal.send:115] Sending query '\x1b[s\x1bPtmux;\x1b\x1b_Gi=4294967295,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\x1b\\\x1b\\\x1b[u\x1b[2K' for KittyGraphicsStatus
2023-05-03 13:55:28 DEBUG   [euporie.core.terminal.send:115] Sending query '\x1bPtmux;\x1b\x1b[>q\x1b\\' for ItermGraphicsStatus
2023-05-03 13:55:28 DEBUG   [euporie.core.terminal.send:115] Sending query '\x1b[?1016$p' for SgrPixelStatus
2023-05-03 13:55:28 INFO    [euporie.core.app.open_file:567] Opening file my-notebook.ipynb
2023-05-03 13:55:28 DEBUG   [euporie.core.app.get_file_tabs:537] File my-notebook.ipynb has mime type: application/x-ipynb+json
2023-05-03 13:55:28 DEBUG   [euporie.core.tabs.notebook.__init__:86] Loading notebooks my-notebook.ipynb
2023-05-03 13:55:28 DEBUG   [euporie.core.kernel.start:375] Imported `ipykernel` to prevent import deadlock
2023-05-03 13:55:28 DEBUG   [euporie.core.kernel.start_:275] Starting kernel
2023-05-03 13:55:28 INFO    [euporie.core.kernel.start_:313] Started kernel python3
2023-05-03 13:55:28 DEBUG   [euporie.core.kernel.post_start_:338] Waiting for kernel to become ready
2023-05-03 13:55:29 DEBUG   [euporie.core.kernel.post_start_:346] Kernel 210bf477-d6c0-4b11-8ba7-cf758c479487 ready
2023-05-03 13:55:29 DEBUG   [euporie.core.kernel.poll:395] Waiting for shell messages
2023-05-03 13:55:29 DEBUG   [euporie.core.kernel.poll:395] Waiting for iopub messages
2023-05-03 13:55:29 DEBUG   [euporie.core.kernel.poll:395] Waiting for stdin messages
2023-05-03 13:55:29 DEBUG   [euporie.core.tabs.base.kernel_started:234] Running 0 kernel tasks
2023-05-03 13:55:29 DEBUG   [euporie.core.history.load:55] Loaded 97 items from kernel history
2023-05-03 13:55:47 ERROR   [euporie.core.convert.core._convert:266] An error occurred during format conversion
Traceback (most recent call last):
  File "euporie-venv/lib/python3.9/site-packages/prompt_toolkit/cache.py", line 40, in get
    return self._data[key]
KeyError: (60, (9, 22))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "euporie-venv/lib/python3.9/site-packages/prompt_toolkit/cache.py", line 40, in get
    return self._data[key]
KeyError: (60, (9, 22))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "euporie-venv/lib/python3.9/site-packages/prompt_toolkit/cache.py", line 40, in get
    return self._data[key]
KeyError: (5488733560907528482, 'base64-png', 'formatted_text', 60, 19, '#F0F0F0', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "euporie-venv/lib/python3.9/site-packages/prompt_toolkit/cache.py", line 40, in get
    return self._data[key]
KeyError: (5488733560907528482, 'base64-png', 'ansi', 60, 19, '#F0F0F0', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "euporie-venv/lib/python3.9/site-packages/euporie/core/convert/core.py", line 261, in _convert
    output = _CONVERSION_CACHE.get(
  File "euporie-venv/lib/python3.9/site-packages/prompt_toolkit/cache.py", line 43, in get
    value = getter_func()
  File "euporie-venv/lib/python3.9/site-packages/euporie/core/convert/formats/common.py", line 163, in chafa_convert_py
    return canvas.print(fallback=True).decode()
  File "euporie-venv/lib/python3.9/site-packages/chafa/chafa.py", line 2560, in print
    term_info = term_db.detect()
  File "euporie-venv/lib/python3.9/site-packages/chafa/chafa.py", line 1829, in detect
    glib = ctypes.CDLL(_lib_glib)
  File "/usr/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libglib-2.0.so: cannot open shared object file: No such file or directory
2023-05-03 13:55:47 ERROR   [euporie.core.convert.core._convert:269] Failed to convert `'iVBORw0KG` from `base64-png` to `formatted_text` using route `['base64-png', 'png', 'pil', 'ansi', 'formatted_text']` at stage `ansi`
2023-05-03 13:55:47 ERROR   [euporie.core.convert.core._convert:266] An error occurred during format conversion
Traceback (most recent call last):
  File "euporie-venv/lib/python3.9/site-packages/prompt_toolkit/cache.py", line 40, in get
    return self._data[key]
KeyError: (60, (9, 22))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "euporie-venv/lib/python3.9/site-packages/prompt_toolkit/cache.py", line 40, in get
    return self._data[key]
KeyError: (60, (9, 22))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "euporie-venv/lib/python3.9/site-packages/prompt_toolkit/cache.py", line 40, in get
    return self._data[key]
KeyError: (5488733560907528482, 'base64-png', 'formatted_text', 60, 19, '#F0F0F0', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "euporie-venv/lib/python3.9/site-packages/prompt_toolkit/cache.py", line 40, in get
    return self._data[key]
KeyError: (5488733560907528482, 'base64-png', 'formatted_text', 60, 19, '#F0F0F0', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "euporie-venv/lib/python3.9/site-packages/euporie/core/convert/core.py", line 261, in _convert
    output = _CONVERSION_CACHE.get(
  File "euporie-venv/lib/python3.9/site-packages/prompt_toolkit/cache.py", line 43, in get
    value = getter_func()
  File "euporie-venv/lib/python3.9/site-packages/euporie/core/convert/formats/formatted_text.py", line 132, in ansi_to_ft
    elif (lexer := detect_lexer(markup, path)) is not None:
  File "euporie-venv/lib/python3.9/site-packages/euporie/core/lexers.py", line 39, in detect_lexer
    lexer = guess_lexer(text)
  File "euporie-venv/lib/python3.9/site-packages/pygments/lexers/__init__.py", line 320, in guess_lexer
    _text, _ = guess_decode(_text)
  File "euporie-venv/lib/python3.9/site-packages/pygments/util.py", line 289, in guess_decode
    text = text.decode('utf-8')
AttributeError: 'list' object has no attribute 'decode'
2023-05-03 13:55:47 ERROR   [euporie.core.convert.core._convert:269] Failed to convert `'iVBORw0KG` from `base64-png` to `formatted_text` using route `['base64-png', 'png', 'pil', 'ansi', 'formatted_text']` at stage `formatted_text`
joouha commented 1 year ago

It appears that you don't have glib2 installed (specifically libglib-2.0.so), which chafa.py apparently requires

twrightsman commented 1 year ago

Strange. I'm running this on Debian Bullseye, which has glib2 installed:

$ apt list --installed libglib2.0*
Listing... Done
libglib2.0-0/stable,now 2.66.8-1 amd64 [installed,automatic]
$ find /usr/lib -name 'libglib*.so.0'
/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
twrightsman commented 1 year ago

After further investigation I found the glib-locating code in chafa.py. It seems it fails to find glib on my machine:

$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes.util
>>> ctypes.util.find_library('libglib-2.0')
>>>

Either way, this doesn't appear to be a euporie issue so I will close this. Thanks!

GuardKenzie commented 1 year ago

Thanks to @twrightsman this has been resolved with chafa.py v1.1.2. :orange_heart:

joouha commented 1 year ago

Thank you so much