【问题标题】:_curses.error: setupterm: could not find terminal, Raspberry Pi_curses.error:setupterm:找不到终端,Raspberry Pi
【发布时间】:2023-04-09 15:13:01
【问题描述】:

每次我在 Raspberry Pi 上运行此脚本时:

import curses
import RPi.GPIO as GPIO

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

motor1a = 7
motor1b = 11
motor1e = 22
motor2a = 13
motor2b = 16
motor2e = 15

GPIO.setup(motor1a,GPIO.OUT)
GPIO.setup(motor1b,GPIO.OUT)
GPIO.setup(motor1e,GPIO.OUT)
GPIO.setup(motor2a,GPIO.OUT)
GPIO.setup(motor2b,GPIO.OUT)
GPIO.setup(motor2e,GPIO.OUT)

screen = curses.initscr()
curses.noecho()  
curses.cbreak()
curses.halfdelay(3)
screen.keypad(True)

try:
    while True:   
        char = screen.getch()
        if char == ord('q'):
            break
        elif char == curses.KEY_UP:
            GPIO.output(motor1a,GPIO.HIGH)
            GPIO.output(motor1b,GPIO.LOW)
            GPIO.output(motor1e,GPIO.HIGH)
            GPIO.output(motor2a,GPIO.HIGH)
            GPIO.output(motor2b,GPIO.LOW)
            GPIO.output(motor2e,GPIO.HIGH)
# except SOMEEXCEPTION is missing here, I am not sure why there is an exception in the first place

我收到一个错误:

_curses.error: setupterm: could not find terminal

我该如何解决这个问题?

我看到一个帖子说要执行以下操作:

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

export TERM=linux ; export TERMINFO=/etc/terminfo

但我不确定在哪里执行该步骤。

【问题讨论】:

  • 这段代码不能工作——缩进在 Python 中是必不可少的。它最后也缺少一块(try: 的关闭)。我修复了它,希望它更像 python(except 仍然丢失)

标签: terminal raspberry-pi ncurses python-curses


【解决方案1】:

为了使用curses,您需要告诉您正在使用哪个终端,以便库可以发送正确的命令。这是通过在运行程序的同一位置运行您在 shell 中提供的命令来完成的

$ export TERM=linux
$ export TERMINFO=/etc/terminfo
$ python3 myprogram.py

$是shell的提示符,你可能还有别的意思)

正如我在评论中提到的,你的代码无论如何都不会运行,try 后面缺少一个except(我不确定你需要try 做什么,你需要了解这一点无论如何,为了捕获正确的异常)

【讨论】:

    猜你喜欢
    • 2018-11-14
    • 2014-11-07
    • 2020-10-21
    • 1970-01-01
    • 2013-12-07
    • 2021-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多