Python Forum
mouse library demands root access
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mouse library demands root access
#1
Using either pip3 install mouse and sudo pip3 install mouse generate the following error when importing the library into a script (Autokey).

# [win + z]

import mouse, time

i = 1
while i < 2:
    mouse.move(265, 116, absolute=True, duration=0.2)
    time.sleep(0.2)
    keyboard.wait_for_keypress("<escape>", timeOut=1.0)
    mouse.click("right") ###
    time.sleep(0.2)
    keyboard.send_keys("<alt>+<shift>+s")
    i = 1
What am I doing wrong?

Error:
Traceback (most recent call last): File "/home/ineuw/.local/lib/python3.8/site-packages/autokey/service.py", line 530, in _execute exec(compiled_code, scope) File "/home/ineuw/.config/autokey/data/macros/win-z.py", line 10, in <module> mouse.click("right") File "/home/ineuw/.local/lib/python3.8/site-packages/mouse/__init__.py", line 93, in click _os_mouse.press(button) File "/home/ineuw/.local/lib/python3.8/site-packages/mouse/_nixmouse.py", line 105, in press build_device() File "/home/ineuw/.local/lib/python3.8/site-packages/mouse/_nixmouse.py", line 72, in build_device ensure_root() File "/home/ineuw/.local/lib/python3.8/site-packages/mouse/_nixcommon.py", line 165, 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.
Linux Mint Cinnamon 21.3 - Python 3.10.12 - Autokey-gtk 0.96.0 as of 2024-01-13.
Reply
#2
You need to run your program as root. It is listed as a limitation of the package.
Quote:Known limitations:
To avoid depending on X the Linux parts reads raw device files (/dev/input/input*) but this requries root.
Have you lookd at PyAutoGUI?
Reply
#3
Apologies for the delay in replying. Many thanks for your advice. PyAutoGUI is installed, but haven't used it yet. That's next.
Linux Mint Cinnamon 21.3 - Python 3.10.12 - Autokey-gtk 0.96.0 as of 2024-01-13.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  mouse 0.7.0 - mouse polling hate 125-1000hz penahuse 1 2,465 Dec-06-2019, 09:51 PM
Last Post: Larz60+
  unable to pass a input after changing the user from root to non root using python avinash 3 3,128 Apr-08-2019, 10:05 AM
Last Post: avinash
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,745 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020