问题描述
我正在尝试使用 Python(使用 PyCharm 2.0)运行一个简单的 curses 脚本.
这是我的脚本:
导入诅咒stdscr = curses.initscr()诅咒.noecho()诅咒.cbreak()stdscr.keypad(1)而 1:c = stdscr.getch()if c == ord('p'): print("我按下了p")elif c == ord('q'): 中断诅咒.nocbreak();stdscr.keypad(0);诅咒.echo()诅咒.endwin()
当我从我的 IDE (PyCharm 2) 运行它时,我收到以下错误:
_curses.error: setupterm: 找不到终端进程以退出代码 1 结束如果我从 bash 运行脚本,它只会卡在 while 循环中,对按 p 或 q 没有反应.
任何帮助将不胜感激.
你必须设置环境变量TERM
和TERMINFO
,像这样:
export TERM=linux导出 TERMINFO=/etc/terminfo
并且,如果您的设备没有这个目录 (/etc/terminfo
),请制作它并复制 terminfo 数据库.
对于linux"和pcansi"终端,您可以下载数据库:
- http://forum.xda-developers.com/attachment.php?attachmentid=2134052&d=1374459598
- http://forum.xda-developers.com/showthread.php?t=552287&page=4
I am trying to get a simple curses script to run using Python (with PyCharm 2.0).
This is my script:
import curses
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)
while 1:
c = stdscr.getch()
if c == ord('p'): print("I pressed p")
elif c == ord('q'): break
curses.nocbreak(); stdscr.keypad(0); curses.echo()
curses.endwin()
When I run this from my IDE (PyCharm 2) I get the following error:
_curses.error: setupterm: could not find terminal
Process finished with exit code 1
If I run the script from bash it will simply be stuck in the while loop not reacting to either pressing p or q.
Any help would be appreciated.
You must set enviroment variables TERM
and TERMINFO
, like this:
export TERM=linux
export TERMINFO=/etc/terminfo
And, if you device have no this dir (/etc/terminfo
), make it, and copy terminfo database.
For "linux", and "pcansi" terminals you can download database:
- http://forum.xda-developers.com/attachment.php?attachmentid=2134052&d=1374459598
- http://forum.xda-developers.com/showthread.php?t=552287&page=4
这篇关于Setupterm 找不到终端,在 Python 程序中使用 Curses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!