Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
turbobato opened this issue Jan 16, 2025 · 2 comments
Open
2 tasks done
Labels

Comments

@turbobato
Copy link

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
@keltecc
Copy link

keltecc commented Jan 17, 2025

Please, try this:

import os
os.environ['TERM'] = 'linux'

import pwn

It works for me.

@turbobato
Copy link
Author

This works ! However, why is the TERM environment variable unset by sage ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants