I am trying to run the motors.py file that came with the robot hat. I have run the installer, I am on a Raspberry pi 4. When I try to import motors and create new Motors, motors = Motors(), I keep getting this error: NameError: name ‘User’ is not defined
My username is pi.
pi@raspberrypi:~/code $ /usr/bin/python /home/pi/code/MotorControlBoard/motors.py
File “/home/pi/code/MotorControlBoard/motors.py”, line 3, in
motors = Motors()
File “/usr/local/lib/python3.13/dist-packages/robot_hat/motor.py”, line 140, in init
self.db = fileDB(db=db, mode=‘774’, owner=User)
^^^^
NameError: name ‘User’ is not defined
Take this with a pinch of salt, as I’ve only had a quick glance and may be wrong, but as far as I can see the Motors class is meant to be used at a higher level of abstraction, as User is not defined in motors.py. The github examples use the Motor (singular no “s” ) in their examples which looks fine.
So either use the Motor class not Motors or define User first in your file
#at top of your file add
import getpass
User = getpass.getuser()
Or simply
User = “pi”
However you may come across other uninitialized states from the Motors class.
Alternatively, there must be some initialisation lurking in the other files in the package such as __init_. I have not checked.