msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.25k stars 1.21k forks source link

ipython: prompt_toolkit.output.win32.NoConsoleScreenBufferError: Found xterm, while expecting a Windows console. #18455

Open przemoc opened 1 year ago

przemoc commented 1 year ago

Description / Steps to reproduce the issue

ipython fails to start.

  1. Start MSYS2 UCRT64 (I haven't tested other MINGW environments). (in my case: mintty 3.6.5 (x86_64-pc-msys) [Windows 22621])
  2. Install ipython via pacman -S. (in my case: mingw-w64-ucrt-x86_64-python-ipython 8.15.0-1)
  3. Run ipython via ipython or python -m IPython.

Expected behavior

ipython starts without an issue.

Actual behavior

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.

$ ipython
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:/msys64/ucrt64/bin/ipython.exe/__main__.py", line 7, in <module>
    sys.exit(start_ipython())
             ^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/IPython/__init__.py", line 129, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/traitlets/config/application.py", line 1042, in launch_instance
    app.initialize(argv)
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/traitlets/config/application.py", line 113, in inner
    return method(app, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/IPython/terminal/ipapp.py", line 279, in initialize
    self.init_shell()
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/IPython/terminal/ipapp.py", line 293, in init_shell
    self.shell = self.interactive_shell_class.instance(parent=self,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/traitlets/config/configurable.py", line 551, in instance
    inst = cls(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/IPython/terminal/interactiveshell.py", line 856, in __init__
    self.init_prompt_toolkit_cli()
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/IPython/terminal/interactiveshell.py", line 635, in init_prompt_toolkit_cli
    self.pt_app = PromptSession(
                  ^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/shortcuts/prompt.py", line 466, in __init__
    self.app = self._create_application(editing_mode, erase_when_done)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/shortcuts/prompt.py", line 717, in _create_application
    application: Application[_T] = Application(
                                   ^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/application/application.py", line 265, in __init__
    self.output = output or session.output
                            ^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/application/current.py", line 68, in output
    self._output = create_output()
                   ^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/output/defaults.py", line 87, in create_output
    return Win32Output(stdout, default_color_depth=color_depth_from_env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/output/win32.py", line 116, in __init__
    info = self.get_win32_screen_buffer_info()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/output/win32.py", line 220, 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.

If you suspect this is an IPython 8.15.0 bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    c.Application.verbose_crash=True

Verification

Windows Version

MINGW64_NT-10.0-22621

MINGW environments affected

Are you willing to submit a PR?

No response

brisingraerowing commented 1 year ago

You might need to wrap it using winpty for it to work with MINTTY. There should probably be a wrapper script for that.

raedrizqie commented 1 year ago

i cant reproduce those errors..

$ python -m IPython
Python 3.11.5 (main, Aug 27 2023, 19:14:05)  [GCC UCRT 13.2.0 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.15.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:
$ ipython
Python 3.11.5 (main, Aug 27 2023, 19:14:05)  [GCC UCRT 13.2.0 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.15.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:
przemoc commented 8 months ago

Currently with following software:

running ipython or python -m IPython from MSYS2 UCRT64 gives:

$ ipython
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:/msys64/ucrt64/bin/ipython.exe/__main__.py", line 7, in <module>
    sys.exit(start_ipython())
             ^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/IPython/__init__.py", line 130, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/traitlets/config/application.py", line 1074, in launch_instance
    app.initialize(argv)
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/traitlets/config/application.py", line 118, in inner
    return method(app, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/IPython/terminal/ipapp.py", line 278, in initialize
    self.init_shell()
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/IPython/terminal/ipapp.py", line 292, in init_shell
    self.shell = self.interactive_shell_class.instance(parent=self,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/traitlets/config/configurable.py", line 583, in instance
    inst = cls(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/IPython/terminal/interactiveshell.py", line 866, in __init__
    self.init_prompt_toolkit_cli()
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/IPython/terminal/interactiveshell.py", line 646, in init_prompt_toolkit_cli
    self.pt_app = PromptSession(
                  ^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/shortcuts/prompt.py", line 467, in __init__
    self.app = self._create_application(editing_mode, erase_when_done)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/shortcuts/prompt.py", line 718, in _create_application
    application: Application[_T] = Application(
                                   ^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/application/application.py", line 267, in __init__
    self.output = output or session.output
                            ^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/application/current.py", line 67, in output
    self._output = create_output()
                   ^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/output/defaults.py", line 87, in create_output
    return Win32Output(stdout, default_color_depth=color_depth_from_env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/output/win32.py", line 115, in __init__
    info = self.get_win32_screen_buffer_info()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/ucrt64/lib/python3.11/site-packages/prompt_toolkit/output/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.

If you suspect this is an IPython 8.19.0 bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    c.Application.verbose_crash=True

so the same problem as originally reported: 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 exporting different TERM, e.g. mintty, but then error was: prompt_toolkit.output.win32.NoConsoleScreenBufferError: No Windows console found. Are you running cmd.exe?

It seems that winpty indeed helps, but it feels more like workaround than solution.

$ winpty ipython
Python 3.11.7 (main, Dec  7 2023, 09:09:57)  [GCC UCRT 13.2.0 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: