首页 > 解决方案 > 导入 pwn 在 PyCharm 中崩溃,但在从终端运行时有效

问题描述

当我尝试import pwn在 PyCharm 中运行该行时,它会崩溃并显示以下错误消息:

/usr/local/bin/python3.8 /Users/ianzhang/Documents/Coding/CTF/buffer_overflow1.py
Warning: _curses.error: setupterm: could not find terminfo database

Traceback (most recent call last):
  File "/Users/ianzhang/Documents/Coding/CTF/buffer_overflow1.py", line 1, in <module>
    import pwn
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pwn/__init__.py", line 4, in <module>
    from pwn.toplevel import *
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pwn/toplevel.py", line 20, in <module>
    import pwnlib
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pwnlib/__init__.py", line 43, in <module>
    importlib.import_module('.%s' % module, 'pwnlib')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pwnlib/args.py", line 62, in <module>
    from pwnlib import term
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pwnlib/term/__init__.py", line 6, in <module>
    from pwnlib.term import completer
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pwnlib/term/completer.py", line 7, in <module>
    from pwnlib.term import readline
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pwnlib/term/readline.py", line 13, in <module>
    from pwnlib.term import text
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pwnlib/term/text.py", line 126, in <module>
    sys.modules[__name__] = Module()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pwnlib/term/text.py", line 49, in __init__
    s = termcap.get(y)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pwnlib/term/unix_termcap.py", line 28, in get
    s = curses.tigetstr(cap)
_curses.error: must call (at least) setupterm() first

Process finished with exit code 1

但是,当我从终端执行文件时,它运行良好。

我试图找到类似的问题,但似乎其他人有错误ImportError: cannot import name ENUM_P_TYPE而不是我的错误。

我在 macOS 10.15.4 上运行它。

标签: pythonpycharmpwntools

解决方案


问题是由于这个,Warning: _curses.error: setupterm: could not find terminfo database导致curses抛出错误和异常。

解决方案应该是导出终端变量

$ export TERM=linux
$ export TERMINFO=/bin/zsh

但是对于pycharm,需要在pycharm的配置里面完成。

基于这个答案,它应该设置从Edit Configurations -> Environment variables并设置名称值对。

TERM linux

TERMINFO /etc/zsh

推荐阅读