jktr / matplotlib-backend-kitty

show matplotlib plots directly in your kitty terminal
Creative Commons Zero v1.0 Universal
137 stars 16 forks source link

upstream regression in kitty 0.24.4 (ValueError: invalid literal for int() with base 10: '') #5

Closed julianfritzsch closed 2 years ago

julianfritzsch commented 2 years ago

Hi, I'm getting the following error trying to use the package: ValueError: invalid literal for int() with base 10: '' Here is the full stack trace

  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/pandas/plotting/_core.py", line 1758, in hexbin
    return self(kind="hexbin", x=x, y=y, C=C, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/pandas/plotting/_core.py", line 917, in __call__
    return plot_backend.plot(data, x=x, y=y, kind=kind, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/pandas/plotting/_matplotlib/__init__.py", line 72, in plot
    plot_obj.draw()
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py", line 323, in draw
    self.plt.draw_if_interactive()
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/matplotlib/pyplot.py", line 319, in draw_if_interactive
    return _backend_mod.draw_if_interactive(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/matplotlib-backend-kitty/__init__.py", line 79, in draw_if_interactive
    cls.show()
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/matplotlib-backend-kitty/__init__.py", line 83, in show
    _Backend.show(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 3524, in show
    manager.show()  # Emits a warning for non-interactive backend.
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/matplotlib-backend-kitty/__init__.py", line 44, in show
    px = list(map(int, px.split('x')))
ValueError: invalid literal for int() with base 10: '' 

I am using Kitty 0.24.4 under MacOS 12.3 with Python 3.8.13 installed with Conda and Matplotlib 3.5.1

jktr commented 2 years ago

I am using Kitty 0.24.4 under MacOS 12.3 with Python 3.8.13 installed with Conda and Matplotlib 3.5.1

This module currently relies on running kitty +kitten icat --print-window-size as a subprocess. On kitty 0.24.4, this seems to fail with the following, at least on my end:

$ kitty +kitten icat --print-window-size
Traceback (most recent call last):
  File "/nix/store/hb1lzaisgx2m9n29hqhh6yp6hasplq1v-python3-3.9.10/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/nix/store/hb1lzaisgx2m9n29hqhh6yp6hasplq1v-python3-3.9.10/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/nix/store/difdrdflm2al35f1pqmqkkazrkfaxqm8-kitty-0.24.4/bin/../lib/kitty/__main__.py", line 185, in <module>
    main()
  File "/nix/store/difdrdflm2al35f1pqmqkkazrkfaxqm8-kitty-0.24.4/bin/../lib/kitty/__main__.py", line 176, in main
    namespaced(['+', first_arg[1:]] + sys.argv[2:])
  File "/nix/store/difdrdflm2al35f1pqmqkkazrkfaxqm8-kitty-0.24.4/bin/../lib/kitty/__main__.py", line 129, in namespaced
    func(args[1:])
  File "/nix/store/difdrdflm2al35f1pqmqkkazrkfaxqm8-kitty-0.24.4/bin/../lib/kitty/__main__.py", line 112, in run_kitten
    rk(kitten)
  File "/nix/store/difdrdflm2al35f1pqmqkkazrkfaxqm8-kitty-0.24.4/bin/../lib/kitty/kittens/runner.py", line 120, in run_kitten
    runpy.run_module(f'kittens.{kitten}.main', run_name=run_name)
  File "/nix/store/hb1lzaisgx2m9n29hqhh6yp6hasplq1v-python3-3.9.10/lib/python3.9/runpy.py", line 213, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "/nix/store/hb1lzaisgx2m9n29hqhh6yp6hasplq1v-python3-3.9.10/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/nix/store/difdrdflm2al35f1pqmqkkazrkfaxqm8-kitty-0.24.4/bin/../lib/kitty/kittens/icat/main.py", line 613, in <module>
    main()
  File "/nix/store/difdrdflm2al35f1pqmqkkazrkfaxqm8-kitty-0.24.4/bin/../lib/kitty/kittens/icat/main.py", line 518, in main
    ss = screen_size_function(tty)()
  File "/nix/store/difdrdflm2al35f1pqmqkkazrkfaxqm8-kitty-0.24.4/bin/../lib/kitty/kitty/utils.py", line 176, in __call__
    self.ans = read_screen_size(self.fd)
  File "/nix/store/difdrdflm2al35f1pqmqkkazrkfaxqm8-kitty-0.24.4/bin/../lib/kitty/kitty/utils.py", line 156, in read_screen_size
    if fd < 0:
TypeError: '<' not supported between instances of '_io.TextIOWrapper' and 'int'

So this looks like a regression in kitty's tooling, for which someone has already opended an issue upstream: https://github.com/kovidgoyal/kitty/issues/4900

I'll leave this open until upstream rolls out a fix.

jktr commented 2 years ago

Actually, this seems to have already been fixed on kitty master: https://github.com/kovidgoyal/kitty/pull/4818

So you could wait for 0.24.5 to be released, run kitty nightly in the meantime, or downgrade.

julianfritzsch commented 2 years ago

Interestingly, with kitty 0.25.0 it works when using iPython but using a Jupyter console it still gives the same error.

jktr commented 2 years ago

kitty 0.25.0 and 0.25.1 have been released and are likely available in most distros' repos by now; both of them seem to work fine on my end. My thanks go out to @nertro for fixing this issue upstream.

lkhphuc commented 1 year ago

Hi @julianfritzsch , I just want to ask if you have found any solution for this error on Jupyter Console?

julianfritzsch commented 1 year ago

Hi, unfortunately it does not work with the Jupyter console for me but I get an error

Error: Failed to open controlling terminal with error: open /dev/tty: device not configured

However, it works perfectly fine with iPython for me