andreped/super-ml-pets

Keyboard events require sudo on Ubuntu

tno123 opened this issue · 2 comments

Tested deployment on Ubuntu.
Also needed to install tkinter as an additional requirement.

ran it with

sudo su
source venv/bin/activate
xhost +
export DISPLAY=:0.0

Traceback (most recent call last):
File "main.py", line 37, in
pause()
File "/home/xxx/super-ml-pets/src/agent.py", line 22, in pause
if keyboard.read_key() == 'space':
File "/home/xxx/super-ml-pets/venv/lib/python3.8/site-packages/keyboard/init.py", line 935, in read_key
event = read_event(suppress)
File "/home/xxx/super-ml-pets/venv/lib/python3.8/site-packages/keyboard/init.py", line 924, in read_event
hooked = hook(queue.put, suppress=suppress)
File "/home/xxx/super-ml-pets/venv/lib/python3.8/site-packages/keyboard/init.py", line 461, in hook
append(callback)
File "/home/xxx/super-ml-pets/venv/lib/python3.8/site-packages/keyboard/_generic.py", line 67, in add_handler
self.start_if_necessary()
File "/home/xxx/super-ml-pets/venv/lib/python3.8/site-packages/keyboard/_generic.py", line 35, in start_if_necessary
self.init()
File "/home/xxx/super-ml-pets/venv/lib/python3.8/site-packages/keyboard/init.py", line 196, in init
_os_keyboard.init()
File "/home/xxx/super-ml-pets/venv/lib/python3.8/site-packages/keyboard/_nixkeyboard.py", line 113, in init
build_device()
File "/home/xxx/super-ml-pets/venv/lib/python3.8/site-packages/keyboard/_nixkeyboard.py", line 109, in build_device
ensure_root()
File "/home/xxx/super-ml-pets/venv/lib/python3.8/site-packages/keyboard/_nixcommon.py", line 174, in ensure_root
raise ImportError('You must be root to use this library on linux.')
ImportError: You must be root to use this library on linux.

I updated the README to have the additional setup steps required: f1aeca7

Regarding the sudo stuff, we likely have to remove keyboard from requirements, and use a separate solution to capture key events.

I will open a new issue regarding handling the sudo stuff in the future. But as it works on Ubuntu now, I think the main issue is solved.