Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Terminal _curses.error:setupterm:找不到终端,Raspberry Pi_Terminal_Raspberry Pi_Ncurses_Python Curses - Fatal编程技术网

Terminal _curses.error:setupterm:找不到终端,Raspberry Pi

Terminal _curses.error:setupterm:找不到终端,Raspberry Pi,terminal,raspberry-pi,ncurses,python-curses,Terminal,Raspberry Pi,Ncurses,Python Curses,每次我在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)

每次我在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
我怎样才能解决这个问题

我看到一个帖子,上面说要做以下事情:

必须设置环境变量TERM和TERMINFO,如下所示:

导出术语=linux;导出TERMINFO=/etc/TERMINFO

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

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

$ export TERM=linux
$ export TERMINFO=/etc/terminfo
$ python3 myprogram.py
$是shell的提示,您可能还有其他内容


正如我在评论中提到的,您的代码无论如何都不会运行,尝试后缺少一个except。我不确定您需要尝试的目的是什么,您无论如何都需要了解这一点,以便捕获正确的异常

此代码无法工作-缩进在Python中是必不可少的。它在try结束时还缺少一个片段:。我修复了它,希望它更像python,但仍然缺少