0

I'm trying to close my program when the esc key is pressed. For this I found the keyboard library.

import keyboard #pip install keyboard

t=0
while True:
    print (t)
    t=t+1
    if keyboard.is_pressed('esc'):
        print('STOP prog')
        break

In windows (pycharm) works perfect. But when I do it with my raspberry appears this error.

Traceback (most recent call last):
  File "/home/pi/Miguel/thesis/face_detection_applicationv2.py", line 151, in <module>
    main()
  File "/home/pi/Miguel/thesis/face_detection_applicationv2.py", line 137, in main
    if keyboard.is_pressed('esc'):
  File "/usr/local/lib/python3.5/dist-packages/keyboard/__init__.py", line 408, in is_pressed
    _listener.start_if_necessary()
  File "/usr/local/lib/python3.5/dist-packages/keyboard/_generic.py", line 35, in start_if_necessary
    self.init()
  File "/usr/local/lib/python3.5/dist-packages/keyboard/__init__.py", line 194, in init
    _os_keyboard.init()
  File "/usr/local/lib/python3.5/dist-packages/keyboard/_nixkeyboard.py", line 113, in init
    build_device()
  File "/usr/local/lib/python3.5/dist-packages/keyboard/_nixkeyboard.py", line 109, in build_device
    ensure_root()
  File "/usr/local/lib/python3.5/dist-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.**

Somebody knows why is happening this?

If I do pip list keyboard appears.

  • Require admin right for opening /dev/input probably (ls /dev ok) (cat /dev/input failed) ?.. on windows you have UAC and other ... maybe you have installed this with administrator and then you have no error. have you try : sudo python yourprogram.py on RPi? – Ephemeral Jul 8 '19 at 8:16
  • stackoverflow.com/questions/48796147/… Check this thread out on Stack overflow – Stack overflow advertising bro Jul 25 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.