1

I am pretty new to raspberry and Linux. I am trying to run basic example of python library uinput on Raspbian (r Pi 3 B) with following code:

import uinput

device = uinput.Device([
        uinput.BTN_LEFT,
        uinput.BTN_RIGHT,
        uinput.REL_X,
        uinput.REL_Y,
        ])

for i in range(20):
    device.emit(uinput.REL_X, 5)
    device.emit(uinput.REL_Y, 5)

I get the error:

Traceback (most recent call last):

File "/home/pi/Desktop/t1.py", line 7, in uinput.REL_Y, File "/home/pi/.local/lib/python3.5/site-packages/uinput/init.py", line 178, in init self.uinput_fd = fd or fdopen() File "/home/pi/.local/lib/python3.5/site-packages/uinput/__init.py", line 84, in fdopen return _libsuinput.suinput_open() File "/home/pi/.local/lib/python3.5/site-packages/uinput/init.py", line 70, in _open_error_handler raise OSError(code, msg)

OSError: [Errno 19] Failed to open the uinput device: No such device What is wrong? What do I need to change and where?

okram
  • 810
  • 3
  • 11
  • 17

1 Answers1

6

Is the uinput driver module loaded?

Try:

$ lsmod | grep uinput

Probably that will display nothing, which would mean that the driver is not loaded. Try loading it:

$ modprobe uinput

Then try your Python code. If you are not running your code with root privileges you will probably then get a PermissionError due to the access permissions on the /dev/uinput device file.

mhawke
  • 84,695
  • 9
  • 117
  • 138
  • you were right, your first command printed nothing. the second command i had to run with sudo and python code then gave exactly the error you say. – okram Feb 06 '18 at 11:08
  • then it starts to throw "ImportError: No module named 'uinput'". – okram Feb 06 '18 at 11:14
  • if i run script without sudo and right after import i insert line print(uinput) it prints `` which i guess is correct – okram Feb 06 '18 at 11:20
  • Are you using a virtual environment? I am not really that familiar with `uinput` so I could be wrong, but since it involves device drivers I would expect that it should be used only by privileged users. – mhawke Feb 06 '18 at 11:39
  • well, i dont know how to answer at all. how do i know if i run a virtual environment? – okram Feb 06 '18 at 11:43
  • If you don't know then you probably aren't using one, however, why can't your root user load the module? Install `python-uinput` in the global site packages. – mhawke Feb 06 '18 at 11:51
  • 1
    so i added it using pip3 and managed to run that example code (had to `import time` library and add to loop line `time.sleep(0.5)` to see anything happen but that is already another story). Thanks a ton for the quick help! – okram Feb 06 '18 at 12:35