Keep getting same error, can't solve it

I am trying to control my Devastator tank, powered by a Raspberry Pi B3, PiHut MotorShield and mini WiFi keyboard. I am receiving the error setupterm cannot find keyboard. Below is my code:

import curses  
import PiMotor 
import time
import curses
import os  # added so we can shutdown OK

#Name of Individual MOTORS
m1 = PiMotor.Motor("MOTOR1",1)
m2 = PiMotor.Motor("MOTOR2",1)

#To drive all motors together
motorAll = PiMotor.LinkedMotors(m1,m2)

#Names for Individual Arrows
ab = PiMotor.Arrow(1)
al = PiMotor.Arrow(2)
af = PiMotor.Arrow(3) 
ar = PiMotor.Arrow(4)

# Get the curses window, turn off echoing of keyboard to screen, turn off     
# instant (no waiting) key response, and use special values for curser keys
screen = curses.initscr()
curses.noecho()
curses.cbreak()
screen.keypad(True)

##This segment drives the motors in the direction listed below:
## forward and reverse takes speed in percentage(0-100)

try:
    while True:
        char = screen.getch()
        if char == ord('q'):
            break
        if char == ord('S'):  # Added for shutdown on capital S
            os.system ('sudo shutdown now')   # shutdown right now!
        elif char == curses.KEY_UP:
            af.on()
            motorAll.forward(100) 
        elif char == curses.KEY_DOWN:
            af.off()
            ab.on()
            motorAll.reverse(100) 
        elif char == curses.KEY_RIGHT:
            ar.on()
            ab.off()
            m1.reverse(100)
            m2.forward(100)
        elif char == curses.KEY_LEFT:
            ar.off()
            al.on()
            m1.forward(100)
            m2.reverse(100)
        elif char == 10:
            motorALL.stop()

except KeyboardInterupt:
    #Close down curses properly, inc turn echo back on!
    curses.nobreak(); screen.keypad(0); curses.echo(0)
    curses.endwin()

I have used “curses” with mini keyboard before, but this time I am getting the error setupterm cannot find keyboard. Can anyone help me resolve this issue?

The error setupterm cannot find keyboard is usually caused by a missing or incorrect terminal definition. To resolve this issue, you can try the following steps:

  1. Make sure you have the necessary dependencies installed. In your case, you need to install the ncurses library by running the following command:
sudo apt-get install libncurses5-dev
  1. Check if the TERM environment variable is set correctly. You can do this by running the command echo $TERM. It should output xterm or xterm-256color. If it’s not set correctly, you can set it manually by running:
export TERM=xterm
  1. If the above steps don’t work, you can try running your Python script with elevated privileges using sudo. This can sometimes help with access issues related to the keyboard. Run the script with the following command:
sudo python your_script.py

By following these steps, you should be able to resolve the setupterm cannot find keyboard error and control your Devastator tank using your Raspberry Pi B3, PiHut MotorShield, and mini WiFi keyboard.