Setupterm 找不到终端,在 Python 程序中使用 Curses [英] Setupterm could not find terminal, in Python program using curses

查看:55
本文介绍了Setupterm 找不到终端,在 Python 程序中使用 Curses的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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 没有反应.

任何帮助将不胜感激.

解决方案

你必须设置环境变量TERMTERMINFO,像这样:

export TERM=linux导出 TERMINFO=/etc/terminfo

并且,如果您的设备没有这个目录 (/etc/terminfo),请制作它并复制 terminfo 数据库.

对于linux"和pcansi"终端,您可以下载数据库:

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:

这篇关于Setupterm 找不到终端,在 Python 程序中使用 Curses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆