Skip to content

ncurses terminfo error when trying to import pwntools from a sage script #39334

@gjazeron

Description

@gjazeron

Steps To Reproduce

  1. MacOS Sonoma 14.7.1
  2. With sagemath 10.4 installed using the 3-manifolds binary, with pwntools installed using %pip install pwntools in a sage shell
  3. Create a .sage file containing import pwn
  4. Run this file in a terminal, e.g in macOS Terminal
  5. I get the following error : File "/Users/gjazeron/Library/SageMath-10-4/lib/python3.12/site-packages/colored_traceback/colored_traceback.py", line 34, in _get_term_color_support curses.setupterm() _curses.error: setupterm: could not find terminfo database(see below for full trace)

Expected Behavior

Expecting the import to work correctly

Actual Behavior

I get the following error :

$ sage ~/test.sage
Warning: _curses.error: setupterm: could not find terminfo database

Terminal features will not be available.  Consider setting TERM variable to your current terminal name (or xterm).
Traceback (most recent call last):
  File "/Users/gjazeron/Documents/cryptohack/bespoke_padding.sage.py", line 7, in <module>
    import pwn
  File "/Users/gjazeron/Library/SageMath-10-4/lib/python3.12/site-packages/pwn/__init__.py", line 4, in <module>
    from pwn.toplevel import *
  File "/Users/gjazeron/Library/SageMath-10-4/lib/python3.12/site-packages/pwn/toplevel.py", line 92, in <module>
    colored_traceback.add_hook()
  File "/Users/gjazeron/Library/SageMath-10-4/lib/python3.12/site-packages/colored_traceback/colored_traceback.py", line 78, in add_hook
    colorizer = Colorizer(style, colors, debug)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gjazeron/Library/SageMath-10-4/lib/python3.12/site-packages/colored_traceback/colored_traceback.py", line 64, in __init__
    self.formatter = _determine_formatter(style, colors, debug)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gjazeron/Library/SageMath-10-4/lib/python3.12/site-packages/colored_traceback/colored_traceback.py", line 38, in _determine_formatter
    colors = colors or _get_term_color_support()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gjazeron/Library/SageMath-10-4/lib/python3.12/site-packages/colored_traceback/colored_traceback.py", line 34, in _get_term_color_support
    curses.setupterm()
_curses.error: setupterm: could not find terminfo database

With test.sage being composed of the only line import pwn

Additional Information

I've tried setting the TERM and TERMINFO environment variables, with no success.

After discussing a bit with the maintainer of 3-manifolds MacOS sage project (discussion here) we figured out the issue comes from the following lines in the /venv/bin/sage script

 unset TERM  # See Issue #12263
 # sage-run rejects all command line options as the first argument.
  exec sage-run "$@"

Which is related to issue Issue #12263.

And so even if I set TERM env variable back, it doesn't work.

Environment

  • OS: macOS Sonoma 14.7.1
  • Sage Version: 10.4 from 3-manifold project

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions