ImportError: You must be root to use this library on linux.
See original GitHub issueI am using anaconda on chromebook to be able to use python3.6 on it. My issue is that I am trying to replicate something from the curses module. The thing I am trying to replicate is when I press a key, any key, it reads it back to me immediately, like I press “e”, it shows e. If I then press “o”, it replaces the e with an o.
So this me just guessing to see if it works, but my code rn is:
import keyboard
mans = False
while not mans:
dwn = keyboard.KEY_DOWN
dun = keyboard.on_press(dwn)
print(dun)
and it returns as:
Traceback (most recent call last):
File "keyboardtest.py", line 6, in <module>
dun = keyboard.on_press(dwn)
File "/usr/local/conda3/lib/python3.6/site-packages/keyboard/__init__.py", line 472, in on_press
return hook(lambda e: e.event_type == KEY_UP or callback(e), suppress=suppress)
File "/usr/local/conda3/lib/python3.6/site-packages/keyboard/__init__.py", line 459, in hook
append(callback)
File "/usr/local/conda3/lib/python3.6/site-packages/keyboard/_generic.py", line 67, in add_handler
self.start_if_necessary()
File "/usr/local/conda3/lib/python3.6/site-packages/keyboard/_generic.py", line 35, in start_if_necessary
self.init()
File "/usr/local/conda3/lib/python3.6/site-packages/keyboard/__init__.py", line 194, in init
_os_keyboard.init()
File "/usr/local/conda3/lib/python3.6/site-packages/keyboard/_nixkeyboard.py", line 113, in init
build_device()
File "/usr/local/conda3/lib/python3.6/site-packages/keyboard/_nixkeyboard.py", line 109, in build_device
ensure_root()
File "/usr/local/conda3/lib/python3.6/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.
Note how it says “ImportError: You must be root to use this library on linux.”
Now, normally, using a sudo
would fix it, but python3
is not recognized as a command in sudo for me. When I try using the python
command (without 3 for 3.6) it says that the keyboard
module is non existent, even though it works for python3.6.
I will appreciate any help avaible!
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Hi @Yolotroll101
I’m sorry for being so blunt. I support this library on my free time. Every minute spent helping people set up their environment (which is totally unrelated), is a minute that is not spent on improving the library, or helping people whose only hope of support is posting here.
You have a Python script, with dependencies, that you need to run as root. That’s something you can get help for in a lot of different places.
To avoid leaving this on a sour note, a few more workarounds that may work for you:
which python
,which python3
,sudo which pip3
, etc, to get a feel for where things are for your user and the superuser.The library needs root because it operates the same way as a keylogger: intercepting every keystroke, system wide. On Linux, with tools used here (
/dev/input
files), the kernel restricts this operation only to scripts executed by the superuser. There’s an alternative on the works, to use xlib, but it’s not ready yet.Therefore you must execute the script as superuser. How to do that depends on your system, and is not a question suitable for an issue on this library.
If you just want to create a command-line application mimicking curses, you can use other tools that don’t require running as superuser.