paul-gauthier / aider

aider is AI pair programming in your terminal
https://aider.chat/
Apache License 2.0
18.41k stars 1.71k forks source link

Uncaught NoConsoleScreenBufferError in win32.py line 219 #1434

Open roebi opened 1 week ago

roebi commented 1 week ago

$ aider.exe Terminal does not support pretty output (UnicodeDecodeError) Aider v0.55.0 Main model: gpt-4o-2024-08-06 with diff edit format Weak model: gpt-4o-mini Git repo: .git with 8 files Repo-map: using 1024 tokens, auto refresh Use /help for help, run "aider --help" to see cmd line args

Uncaught NoConsoleScreenBufferError in win32.py line 219

Aider version: 0.55.0 Python version: 3.12.5 Platform: Windows-11-10.0.22621-SP0 Python implementation: CPython Virtual environment: Yes OS: Windows 11 (64bit) Git version: git version 2.46.0.windows.1

An uncaught exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "__main__.py", line 7, in <module>
    sys.exit(main())
             ^^^^^^
  File "main.py", line 694, in main
    coder.run()
  File "base_coder.py", line 729, in run
    user_message = self.get_input()
                   ^^^^^^^^^^^^^^^^
  File "base_coder.py", line 742, in get_input
    return self.io.get_input(
           ^^^^^^^^^^^^^^^^^^
  File "io.py", line 345, in get_input
    session = PromptSession(
              ^^^^^^^^^^^^^^
  File "prompt.py", line 476, in __init__
    self.app = self._create_application(editing_mode, erase_when_done)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "prompt.py", line 727, in _create_application
    application: Application[_T] = Application(
                                   ^^^^^^^^^^^^
  File "application.py", line 267, in __init__
    self.output = output or session.output
                            ^^^^^^^^^^^^^^
  File "current.py", line 67, in output
    self._output = create_output()
                   ^^^^^^^^^^^^^^^
  File "defaults.py", line 87, in create_output
    return Win32Output(stdout, default_color_depth=color_depth_from_env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "win32.py", line 115, in __init__
    info = self.get_win32_screen_buffer_info()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "win32.py", line 219, in get_win32_screen_buffer_info
    raise NoConsoleScreenBufferError
prompt_toolkit.output.win32.NoConsoleScreenBufferError: Found xterm, while expecting a Windows console. Maybe try to run this program using "winpty" or run it in cmd.exe instead. Or otherwise, in case of Cygwin, use the Python executable that is compiled for Cygwin.

i work on a windows system , but for the console i use the git bash. this is if you install git for windows a linux like 'bash' shell / terminal. i have installed aider with pipx. The start command was:

PS: aider offer me to open a issue about this .

roebi commented 1 week ago

same error in the git bash with aider --model groq/llama-3.1-70b-versatile --no-pretty --dark-mode

paul-gauthier commented 1 week ago

Thanks for trying aider and filing this issue.

How are you running aider? I can run it just fine on Windows with git bash.

roebi commented 6 days ago

Hello,

i reinstall 'git for windows', was current Version 2.46.0 from 2040807, and install the same version with Git-2.46.0-64-bit.exe

while i was installing here

image

it is written to start with the prefix 'winpty' ... which works, details see below

On pre selected 'Use MinTTY (the default terminal on MSYS2) ... Windows console programs (such as interactive Python) must launched via winpty to work in MinTTY.


here the answer to your question:

following variants end in the same error

aider --model groq/llama-3.1-70b-versatile aider.exe --model groq/llama-3.1-70b-versatile aider --model groq/llama-3.1-70b-versatile --no-pretty --dark-mode

but after reading the last sentence in the error message:

prompt_toolkit.output.win32.NoConsoleScreenBufferError: Found xterm, while expecting a Windows console. Maybe try to run this program using "winpty" or run it in cmd.exe instead. Or otherwise, in case of Cygwin, use the Python executable that is compiled for Cygwin.

i tried with prefix winpty, : winpty aider --model groq/llama-3.1-70b-versatile --no-pretty --dark-mode winpty aider --model groq/llama-3.1-70b-versatile

I tried it with the prefix winpty, which worked.

may the following info help (MINGW64):

my prompt looks:

@ MINGW64 /c/.../.../ () MINGW64 is the content of the env variable $MSYSTEM with this i ended here: https://stackoverflow.com/questions/37460073/msys-vs-mingw-internal-environment-variables ---------- for me is is okay to close this issue as documented behavior, because with prefix winpty it works for me. of course it works also direct in visual studio code in a bash terminal without winpty prefix. i just update now to Aider version: 0.56.0 ----------
roebi commented 6 days ago

Addition to this: With this enabled 'Enable experimental support for pseudo consoles' This allows running native console programs like Node or Python in a Git Bash window without using winpty, but is unfortunately not quite stable yet. image

the prefix winpty is no more needed. means for example aider --model groq/llama-3.1-70b-versatile works

paul-gauthier commented 5 days ago

There are improvements for this in the main branch. Aider will now revert to a dumb UI if a console is not available on windows.

You can get it by installing the latest version from github:

aider --install-main-branch

If you have a chance to try it, let me know if it works better for you.

roebi commented 4 days ago

Thank you for taking care of it,

first i reinstalled git for windows without this experimental support, to not use winpty.

i installed the main branch this way (because of pipx):

pipx install git+https://github.com/paul-gauthier/aider.git --force
...
installed package aider-chat 0.56.1.dev77+g05b3b3df, installed using Python 3.12.6
...

after that aider works this way:

$ aider --model groq/llama-3.1-70b-versatile
Can't initialize prompt toolkit: Found xterm, while expecting a Windows
console. Maybe try to run this program using "winpty" or run it in cmd.exe
instead. Or otherwise, in case of Cygwin, use the Python executable that is
compiled for Cygwin.
Terminal does not support pretty output (UnicodeDecodeError)
Aider v0.56.1.dev77+g05b3b3df
Model: groq/llama-3.1-70b-versatile with diff edit format
Git repo: .git with 17 files
Repo-map: using 1024 tokens, auto refresh
Use /help <question> for help, run "aider --help" to see cmd line args

>

i try a little around with this 'dumb UI', but at the the end i will use in this case aider starting with

winpty aider ...

If there is such a great console extension, why shouldn't you want to use it.

But with this change the Hint

Maybe try to run this program using "winpty"

is now shown without a Stacktrace

which is definitely a user improvement.

Thanks again.